IssueInputBuilder iib = new IssueInputBuilder();
Calendar currenttime = Calendar.getInstance();
iib.setFieldValue("customfield_15031", new Timestamp((currenttime.getTime()).getTime()));
com.atlassian.jira.rest.client.api.domain.input.CannotTransformValueException: Any of available transformers was able to transform given value. Value is: java.sql.Timestamp: 2018-08-07 12:31:57.73
Hi @Asia,
The Atlassian expects date values in string formats.
You can take a look at this page for examples:
https://developer.atlassian.com/server/jira/platform/performing-issue-operations/
For preparing the date you'll need to:
- Know format of the date (default is "dd/MMM/yy h:mm a" but it can be changed)
- Know the user Time Zone (on behalf of which update will be triggered)
TimeZone timeZone = timeZoneManager.getLoggedInUserTimeZone(); //get current user time zone
String jiraTimeFormat = ComponentAccessor.getApplicationProperties().getString("jira.date.time.picker.java.format");//get date format
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
simpleDateFormat.setTimeZone(timeZone);
String date = simpleDateFormat.format(new Date()); //prepared the date in proper format
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.addCustomFieldValue("customfield_15031", date); //set your field
IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(applicationUser, issue.getId(), issueInputParameters);
if (updateValidationResult.isValid()) {
IssueService.IssueResult updateResult = issueService.update(applicationUser, updateValidationResult);
};
Hope it helps.
I am trying to fetch the datetime value from the ticket and place it in another ticket while creating. But when I try to get the value it is showing in some unparseable format like 2019-01-18 02:02:00.0
I am not getting what is that .0 and when I am trying to set the same value it is throwing an error . what should be placed in newDate() in your code?
Below is my code snippet.
DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm a");
String daterc=formatter.format(issue.getCustomFieldValue(plannedrcdate) as Date);
issueInputParameters.addCustomFieldValue("customfield_15332",daterc)
Am i missing something in code as it is not accepting this string and throwing error message
Invalid date format. Please enter the date in the format "dd/MMM/yy h:mm a".}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vineela Durbha,
Yes, as you can see from my code above the format TO which the date should be converted I get from the Jira properties:
String jiraTimeFormat = ComponentAccessor.getApplicationProperties().getString("jira.date.time.picker.java.format");//get date format
So in your case the code should look something like this:
String jiraTimeFormat = ComponentAccessor.getApplicationProperties().getString("jira.date.time.picker.java.format");
DateFormat formatter = new SimpleDateFormat(jiraTimeFormat);
String daterc=formatter.format(issue.getCustomFieldValue(plannedrcdate));
issueInputParameters.addCustomFieldValue("customfield_15332",daterc);
Have fun,
Kostya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also what is the library to import for timezone.because the line i entered as u suggested above is throwing error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is in jira api.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.timezone.TimeZoneManager;
import java.util.TimeZone
TimeZoneManager should be injected to your component.
The maven dependency for it is jira api:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
Where jira.veriosion is your Jira version.
Kostya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting below error
No such property: timeZoneManager for class
Any help on this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am writing this groovy script under Script Listeners
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using java so you should look for groovy docs something like this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think timeZoneManager.getLoggedInUserTimeZone();
is no more valid for Java8 . Do you have any suggestion for the replacement of this method to get logged in user timezone?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am talking about this
https://docs.oracle.com/javase/8/docs/api/index.html?java/util/TimeZone.html
I dont see any loggedin user method here. SO is there any alternative for the same
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getLoggedInUserTimeZone() is a method of TimeZoneManager, it is Jira API:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.