Forums

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

Update all Subtask Components Field Automatically if anyone Update the Parent Issue Component field

HARIOM MAKWANA January 9, 2023

When I am Using Below Code and Update My Parent issue Components field my Subtask issue Components are not Updating.

----------------------------------------------------------------------------------------------------

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
// current issue
def issue = event.issue as MutableIssue
if (issue.getIssueType().getName() == "Sub-task") {
// the name of the field to check
final String fieldName = "Parent Issue"
// user that will make updates
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// check if a right field was updated
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find
{it.field == "Sub-task"}
if (change) {
def issueManager = ComponentAccessor.getIssueManager()
// get components of parent issue
def components = issue.getParentObject().getComponents()
issue.setComponent(components)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
} else return
} else return

1 answer

0 votes
Patrice Champet
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.
January 9, 2023

Hi,

We have the same behavior simply implemented with Automation for Jira.

For this kind of action, we are using more and more Automation for Jira instead of creating our own scripts in scriptRunner.
Regarding automation and jobs, we keep Scriptrunner for advanced uses only.

So if you have a recent version of Jira DC, or using Jira Cloud, you may take a look to Automation for Jira. 

If any reader have some experiences to share, I will be glad to know how you use Automation for Jira VS Scriptrunner for this kind of job.

 Cheers

HARIOM MAKWANA January 10, 2023

Hi @Patrice Champet ,

Thanks for the opinion, definitely I would have gone for the  automation for Jira But Right now we are not using it.

It would be great if you help me out with the Scrip runner.

NealC
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 20, 2023

I am new to automation, do you have the details on the setup you have used? Thank you

HARIOM MAKWANA September 20, 2023

Hi @NealC 

I have Used this in my JIRA Server.

I am using Script runner 6.16.0

Any Other Details You Need Please Explain ?

Thank You.

NealC
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 20, 2023

Thanks I managed to figure it out with Automation. I think the best way to do this (from what I know) is when a component field changes it will update the sub-task components. I wanted to avoid any general editing also triggering the update (eg. just changing some text in a description field for example). I probably should check to see if the component being changed is for a Story or Task... but this should be fine for now. Thanks for replying straight away

component updates.png

Suggest an answer

Log in or Sign up to answer