Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Groovy to retrieve parent issue name

Junaid Shah
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.
March 27, 2015

Hi,

Trying to retrieve the value of the parent issue in a subtask to return a true or false value based on a string containing a fixed issue name of the parent..

How can I retrieve the value of the parent issue. so I can compare it with a fixed string?

 

Thanks.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Cesare Jacopo Corzani
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.
March 31, 2015

You can test it directly using the Script console by doing something like:

import com.atlassian.jira.issue.Issue
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.customisers.ContextBaseScript
@BaseScript ContextBaseScript script

Issue issue = getIssueOrDefault("ABC-1")
issue.getParentObject()?.getKey()

"ABC-1" is your subtask

That obviously works using the console, in the other cases you just need the last line as Michel suggested so

issue.getParentObject()?.getKey()
Junaid Shah
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.
April 8, 2015

Hi, I understand this is getting the key but if I want the issue name, how would that work out? thank you.

Cesare Jacopo Corzani
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.
April 9, 2015

What do you mean by issue name, the summary? Could you give me an example?

Cesare Jacopo Corzani
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.
April 10, 2015

try the code above and put at the end: issue.getParentObject()?.metaClass.methods*.name.sort().unique() That will print all the methods you can access to from your issue.

0 votes
MichałS
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.
March 27, 2015

Hi,

If you have the subtask object then you can just call

subtask.getParentObject()?.getKey()

to get the parent issue objects key.

Junaid Shah
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.
March 27, 2015

Testing this in a script field I get the error javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: subtask for class: Script17 A stacktrace has been logged.

MichałS
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.
March 27, 2015

Ok then just use issue instead of the subtask. Issue is always the current issue object you are viewing or editing.

TAGS
AUG Leaders

Atlassian Community Events