How do I compare and update a custom field value be subtask and parent in a script listener?

I'm trying to update a custom field when the field is updated on the subtask so the parent shows the new value.

in the Script Listener console, issue.fields.parent.key doesn't work because 'parent' is not a known class in JSON.

I got that line from the Scriptrunner for JIRA Cloud examples.

 

1 answer

It's will work on Listener like that

if(issue.fields.issuetype.subtask == true){    
String parentkey= issue.fields.parent.key  
}

and if you are in script console do this:

 def issueKey = 'COPY-19' // enter you sub task key here

def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
def parentIssue = result.body.fields["parent"]
return parentIssue["key"]
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

298 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you