Confused by ScriptRunner. How do I grab parent field values (Both custom and OOTB)?

JordanB June 6, 2016

I have been fiddling around with Script Runner for a few hours and cant seem to get a grasp on how to get values from a parent object when creating a sub-task (during creation or post function). I just recently lost my code and have decided that its now time for me to ask.

Could someone help me out, or point me in the right direction on how to learn this bit of code? I know it has to be basic, but for some reason I cant wrap my head around it

1 answer

1 vote
Jeremy Gaudet
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 6, 2016

You just have to get the issue's parent using Issue.getParentObject(), then reference the new issue the same way you would the current issue.  For example (where eventIssue is the issue associated with a triggering event in a Script Listener):

Issue parentIssue = eventIssue.getParentObject();
Collection<Version> parentFixVersions = parentIssue.getFixVersions();
JordanB June 6, 2016

Hmm. I think I understand that. I am having to test all of this in the Script Console on a browser, so the auto-code isn't working at all.

For example, if I wanted to find a issue (to test this on), could I do something like:

Issue parentIssue = eventIssue.getParentObject("TestIssueName");
def SummaryValue = parentIssue.summary;

Or is there some other way to get the info out of it. Is there a MSDN of sorts that I could look at that contains all of the functions/modifiers in a variable?

JamieA
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 7, 2016

In Script Console you won't have an "eventIssue" defined. To get a single issue use:

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("ABC-2")
if (issue.isSubTask()) {
    def parent = issue.parentObject
    // ...
}
JamieA
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 7, 2016

Suggest an answer

Log in or Sign up to answer