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 Sign up to answer
Community showcase
Posted Tuesday in Statuspage

Introducing Statuspage Getting Started guides! First up: What is Statuspage?

Over the next several weeks we'll be sharing some of our Getting Started guides here in the community. Throughout this series of posts, we'd love to hear from customers and non-customers ab...

24 views 2 1
Join discussion

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