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

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

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();

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?

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
    // ...
}

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

564 views 2 15
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot