Forums

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

Update fix version of subtask when parent is updated

Aisha M
Contributor
June 3, 2025

I have just started using Scriptrunner on Cloud. I have been using the DC version, and would like to see how the scripting differs between the two.

We have a script that updates the fix version of sub-task when parent fix version is updated. I am trying to recreate this in Cloud , but nothing seems to work. 

Can I please get some help on how this could be achieved.

 

Below is the DC script:

IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)

Issue updatedIssue = event.getIssue()

Collection<Version> fixVersions = new ArrayList<Version>()

fixVersions = updatedIssue.getFixVersions()

Collection<Issue> subTasks = updatedIssue.getSubTaskObjects()

subTasks.each {

    if (it instanceof MutableIssue) {

        ((MutableIssue) it).setFixVersions(fixVersions)

       

        issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED, false)

         

    }

}

2 answers

1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
June 8, 2025

Hi @Aisha M

If you are using ScriptRunner for Jira Cloud, just like for DC, you can use HAPI for Jira Cloud and simplify your coding.

Below is a sample working code for your reference:-

def currentIssue = Issues.getByKey(issue.key as String)

if (currentIssue.isSubTask()) {

def parent = currentIssue.parentObject

currentIssue.update {
setFixVersions {
add("${parent.fixVersions.last()}")

}

}

}

Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications

For more information on ScriptRunner's HAPI for Jira Cloud, please refer to this documentation.

I hope this helps to answer your question. :)

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

Aisha M
Contributor
June 30, 2025

Hi @Ram Kumar Aravindakshan _Adaptavist_ , Let me try the sample script.

But there is a condition being required for the Listener to work. What would be the most appropriate one for our scenario ?

I tried ,

issue.issueType.name = 'Story'

But, this gives an error. I thought this would ensure the script ran on the Story issue type and, fix version gets copied onto the child (Sub-task)
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 7, 2025

Hi @Aisha M

Please clarify: are you trying to add the condition to identify the parent issue type?

If yes, then you should do:-

def currentIssue = Issues.getByKey(issue.key as String)

if (currentIssue.isSubTask()) {

def parent = currentIssue.parentObject

if (parent.issueType.name == 'Story') {
currentIssue.update {
setFixVersions {
add("${parent.fixVersions.last()}")

}

}

}

}

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

0 votes
arielei
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.
June 3, 2025

Hey @Aisha M 

Switch to Automation instead of ScriptRunner in this case.

 

You can simply do the following:

Trigger = "Value changed" on edit (Fix Version)

Branch rule: on all children

Edit work-item: Fix-Version Copy from current work-item.

 

Screenshot 2025-06-03 at 13.40.11.png

Aisha M
Contributor
June 3, 2025

@arielei Thank you for the reply

I can understand that automation could be an easier option. But I really want to understand how the scripts differs between the two, because we have a huge amount of scripts that needs to be adapted to suit the cloud environment. 

arielei
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.
June 10, 2025

Hey @Aisha M 

Did you switch to Automation? 

Aisha M
Contributor
June 30, 2025

Hi ! At this point, we are trying to explore the different options with Cloud. If nothing works out, maybe we might look into Automation.

Suggest an answer

Log in or Sign up to answer