You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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 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.
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.
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.
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
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
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def PSDCF = customFieldManager.getCustomFieldObjectsByName("date1")
def PEDCF = customFieldManager.getCustomFieldObjectsByName("date2")
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.