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()
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.