You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
----------------------------------------------------------------------------------------------------
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
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
Hi @Patrice ,
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am new to automation, do you have the details on the setup you have used? Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.