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

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

To update a date field using script runner Edited

Hi, 

I want to update a Date custom field by adding 90 days to the value of another date custom field. Say, Date1 is today, I want the Date2 field to have the date 90days from today, updated automatically upon a transition using script runner. Below is the script I used, the script ran successfully, but the field value didn't get updated in the ticket. I'm not sure what I have missed. Could you please help me with this. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

Issue issue = issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// the dependent custom field
def dateACF = customFieldManager.getCustomFieldObjectByName('Date1')
def dateB = customFieldManager.getCustomFieldObjectByName("Date2")

// get the value of the date A custom field
def dateAValue = issue.getCustomFieldValue(dateACF) as Date

// If the date field is empty ignore it
if (dateAValue==null) {
return null
}

// build the new date
dateB = Calendar.getInstance()

// copy to the new date the value of the Date A custom field
dateB.setTime(dateAValue)

dateB.add(Calendar.MONTH, 3)

return dateB.getTime()

1 answer

1 accepted

0 votes
Answer accepted

Hi @Ilakiya Srinivasan , you need to update custom field on issue. Your postfunction only returns dateB.getTime() but you're not setting the new date to the field. There is nice example of how to update custom field in postfunction here:

https://library.adaptavist.com/entity/change-the-value-of-a-custom-field-in-a-post-function

Let me know if it helps or you need more help ;)

Thanks @Martin Bayer _MoroSystems_ s_r_o__, it really helps!

However, I actually used the JMWE post function 'Set the value of a field to a constant value or the result of a Groovy expression or Groovy Template' to meet my requirement.

Suggest an answer

Log in or Sign up to answer
TAGS

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