Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add customfieldvalue "Start Date Time"?

Asia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 7, 2018
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

 

1 answer

1 accepted

2 votes
Answer accepted
Kostiantyn Ianovskyi August 27, 2018

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.  

Vineela Durbha
Contributor
January 29, 2019

Hi @Kostiantyn Ianovskyi

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".}

Kostiantyn Ianovskyi January 29, 2019

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

Vineela Durbha
Contributor
January 29, 2019

Also what is the library to import for timezone.because the line i entered as u suggested above is throwing error

Kostiantyn Ianovskyi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 29, 2019

It is in jira api.

Kostiantyn Ianovskyi January 29, 2019
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

Vineela Durbha
Contributor
January 29, 2019

I am getting below error

 No such property: timeZoneManager for class

Any help on this

Kostiantyn Ianovskyi January 29, 2019

Are you using Groovy scripts with script runner?

Vineela Durbha
Contributor
January 29, 2019

 I am writing this groovy script under Script Listeners

Kostiantyn Ianovskyi January 29, 2019
Vineela Durbha
Contributor
January 29, 2019

 tried with the above.but I am getting same error

Vineela Durbha
Contributor
January 29, 2019

 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?

Kostiantyn Ianovskyi January 30, 2019

Do you mean Jira 8?

Vineela Durbha
Contributor
January 30, 2019

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

Kostiantyn Ianovskyi January 30, 2019

getLoggedInUserTimeZone() is a method of TimeZoneManager, it is Jira API:

https://docs.atlassian.com/software/jira/docs/api/7.13.0/com/atlassian/jira/timezone/TimeZoneManagerImpl.html

Suggest an answer

Log in or Sign up to answer