Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Scriptrunner for Jira cloud - Diference between datetime custom fields


All i wanna do is compare 2 custom datetime fields and show the difference in a custom numeric field (in hours if possible)


The closest i got is here:


import java.time.LocalDate
import java.time.LocalDateTime;

import static java.time.temporal.ChronoUnit.MINUTES

def reqagreeddate = LocalDateTime.parse(issue.fields.customfield_10029)
def resolutionDate = LocalDateTime.parse(issue.fields.customfield_10032)
def dateDifference = MINUTES.between(reqagreeddate, resolutionDate)

issueInput.fields.customfield_10031 = dateDifference


but i got the following ERROR 

2019-10-25 18:37:53.523 ERROR - Text '2019-10-25T00:00:00.000-0300' could not be parsed, unparsed text found at index 23



I resolved this by giving up and using an project automation plugin for jira called Automation for jira... Scriptrunner still very poor for cloud version in my opinion. With this new tool i was able to do all i wanted in less than 2h.


2 answers

1 accepted

1 vote
Answer accepted

Hi Jose,

Thank you for your question.

I can confirm that the code suggested above will not work for Jira Cloud due to the fact that the code you have provided is foo ScriptRunner for Jira Server and this will not work as Atlassian only provide a rest API in Jira Cloud and do not provide a Java API in the cloud like they do in Jira Server.

You can see more detailed information on the differences between the cloud and server versions inside of our documentation page located here.

I can confirm that to create a calculated field that calculates the value of two custom fields and stores the value inside a third custom field with ScriptRunner for Jira Cloud that you should use a Script Listener which is configured to fire on the Issue Updated event. 

Finally, I can confirm that we have an example Script Listener script located in the documentation page here which shows how to create a calculated field and I can confirm that this should be used as a reference guide to help create the script which you require.

Kind Regards,


Hi Kristian!


Thank's for your help! 


I was using the post-function ScriptRunner method, but i now see how i can use the Listeners and i can do much more stuff that i wanna do, the only problem is that i only was able to find INTEGER or STRING declarations on the documentation, so i still don't know how to convert a string field to datetime and then extract the time in minutes from it.




Hi Jose,

Thank you for your response.

I can confirm that to get the date field values and to set the date field values that you should refer to the examples which we have in the documentation here as these show how to extract the values from different field types on an issue. 

I can also confirm that to convert the string to a date/timestamp that you will need to use some of the standard groovy methods for parsing dates to do this and I can confirm the page here explains how to do this in more detail

Kind Regards,


Hi there,


I am sure there are some differences between server and cloud but I was able to get this running on the server console, see no reason why it wouldn't run on on a scripted field

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor

IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def PSDCF = customFieldManager.getCustomFieldObjectsByName("date1")[0]
def PEDCF = customFieldManager.getCustomFieldObjectsByName("date2")[0]
def PSDCFV = issue.getCustomFieldValue(PSDCF)
def PEDCFV = issue.getCustomFieldValue(PEDCF)

def DateDiff = PEDCFV - PSDCFV

return DateDiff * 24

 Let me know how you get on with that? you would need some if statements if any of the values were null.

Hey Will!


The code that you posted unfortunally doesn't work,


Thanks for the answer anyway!!


apologies, I didn't realise that Jira server and Jira cloud were so different!

anybody looking for the same problem on Jira server this code does work for Server.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events