Get value of Parent Link field of portfolio using script runner

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 3, 2017

Hello Community users,

 

I am trying to get the value of the "Parent Link" field using the script runner plugin in an scripted field.

I know there is an open issue about - https://jira.atlassian.com/browse/JPOSERVER-1663

I tried in the script console the following script

def issueManager = ComponentAccessor.getIssueManager();
def issue = issueManager.getIssueObject("XYZ-103");

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def parentLink = customFieldManager.getCustomFieldObjectByName('Parent Link');

def customFieldValue = issue.getCustomFieldValue(parentLink);

return customFieldValue

Using this script I see the above output on the screen - "com.atlassian.rm.jpo.env.issues.JiraIssueService" ,  is there a method which I can use on this class to return the issueKey/issueID of the parent Link ? As I can't seem to find in the public SDK/API documentation of the class JiraIssueService in the JPO package hierarhcy.

Also, another way I can see  around this problem is to use JQL search inside the scripted field as the new version of script runner supports portfolio specific functions like "portfolioParentsOf " which can give the parent Link issueKey based on the Epic issueKey.

Please share your opinion.

 

3 answers

2 accepted

4 votes
Answer accepted
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 14, 2018

In case someone else is facing this issue, here's the complete solution -

Basically we can use the below script to display initiative(epic's parent) summary and key in a custom field on the story screen. Basically create a scripted field and add is on story view screen and add the below script to the field and you should see the summary of grand-parent of story type on the story itself. 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');

def parentLink = customFieldManager.getCustomFieldObjectByName('Parent Link');
def epic = issue.getCustomFieldValue(epicLink)

if(epic) { // here we check if the story is connected to an epic
epic = (Issue)epic

if(epic.getCustomFieldValue(parentLink)) { // here we check if epic is connected to an parent (via portfolio)
def parentLinkReference = epic.getCustomFieldValue(parentLink);
def key =(String)parentLinkReference.getKey();
def summary =(String)parentLinkReference.getSummary();

return key.concat(" ").concat(summary)
}
}
return null

 

2 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
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.
July 5, 2017

You should just be able to do something like this: 

import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager();
def issue = issueManager.getIssueObject("XYZ-103");

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def parentLink = customFieldManager.getCustomFieldObjectByName('Parent Link');

def customFieldValue = issue.getCustomFieldValue(parentLink);
def parentKey = customFieldValue.key

return parentKey

 Does that not return the parent's key for you?

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 5, 2017

Indeed, ".key" returns the issueKey, thanks! From where can I find class definition of "com.atlassian.rm.jpo.env.issues.JiraIssueService" as I ddin't know that it had the getKey() method which returns the issueKey.

Joshua Yamdogo @ Adaptavist
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.
July 5, 2017

That's a good question Tarun. It looks like there is actually no published API for JIRA Portfolio, so I can see how it would be difficult to know what method to use.

I'd follow the issue on Atlassian's board here:

https://jira.atlassian.com/browse/JPOSERVER-1814

1 vote
Jonathan Muse _Appfire_
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.
October 17, 2018

Hi, I am the product manager for an add-on called Power Scripts that lets you create the same type of automation as Script Runner. I know this question was already answered but I just wanted to share some information that might be helpful to others who are not groovy developers and are just looking for a solution to their problem. Instead of trying to copy and paste code you don’t understand then crossing your fingers hoping it works, there is an easier solution.

string parentLink = #{TEST-123.Parent Link}; //get parent link
#{TEST-123.Parent Link} = "TEST-567"; //set parent link

Getting the parent link can be done in one simple line and seems a lot easier than all that mumbojumbo I see above. 

guoyunpeng October 25, 2019

hi,use power script get portfolio "Parent Link";

string key = "JIRAGJ-252";

string[] parentIssues = allLinkedIssues(key, "Parent-Child Link", -1);

#exception while executing sil program >> null << sil error on line 7 column 28 null

How can I solve it, thank you

Jonathan Muse _Appfire_
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.
October 25, 2019

Hi guyunpen, the best way to get this resolved is to open a support ticket here - https://jira.cprime.io/servicedesk/customer/portal/2. Be sure to attach the entire script to the ticket. Thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events