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.
Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events