Get value of Parent Link field of portfolio using script runner Edited

Tarun Sapra Community Champion Jul 03, 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.

 

2 answers

2 accepted

This widget could not be displayed.

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 Champion Jul 05, 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.

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

This widget could not be displayed.

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

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

485 views 3 18
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