Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script for setting the value of a parent issue field value?

Cole
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2019

I am trying to have a date field on the parent issue get set to 60 days from the current date when a sub-task is set to the Done status. I'm not copying a field from the sub-task, so I added a Groovy script post function from JMWE and added the following:

import com.atlassian.jira.component.ComponentAccessor

import java.sql.Timestamp

issue.parentObject.setDueDate(new Timestamp((new Date() + 60).time))

//issue.parentObject.getKey();
//issue.parentObject.getDueDate();

 

Using the bottom two lines I tested the script to make sure it was pulling the sub-tasks parent issue key, and then I tested what the parent due date field would be and it all checked out. However, whenever I mark this sub-task as done nothing happens. I even have it set to fail the transition if there is an error in the post-function, but that doesn't even happen. Am I missing something in my script or is there possibly a better way to do this?

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
February 7, 2019

You should instead use the Set Field Value of Linked Issues post-function, pick the Due Date field and the "is subtask of" link type, and specify this as the value:

new Date() + 60
Cole
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 8, 2019

I saw that post function type, but didn't investigate it enough apparently. In my head I thought it would set all linked issues. I did not realize you could specify the link type or add custom Groovy.

Just set it up as you said and it works perfectly. Thank you!

Suggest an answer

Log in or Sign up to answer