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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner for Jira cloud - Diference between datetime custom fields Edited

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,

Kristian

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.

 

Thanks!

José

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,

Kristian

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!!

José

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
TAGS
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

238 views 5 13
Read article

Community Events

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

Events near you