Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Tarun Sapra Community Leader 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.

 

3 answers

2 accepted

1 vote
Answer accepted

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 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

1 vote
Answer accepted

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

 

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. 

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

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
Community showcase
Published in Marketplace Apps & Integrations

Do Not Lose your Customer’s Trust

Missing deadlines is one of the biggest problems every team lead wants to avoid when dealing with managed services. When the customer contracts your company to help with IT services it is expected th...

24 views 0 0
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you