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

how to get value of linked issue to the issue by using scriptfield

Muthu kader sahib March 26, 2015

how to get value of linked issue to the issue by using scriptfield.

I have one issue that is linked to another issue.I need one value to show from linked issue to current issue.So i create one script field and try to get linked issue field value.But i'm unable to get that value.Kindly help me to explore JIRA.

This is my code

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;

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

def componentManager = ComponentManager.getInstance()
def issueLinkManager = componentManager.getIssueLinkManager()

def totalRemaining = 0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Version") {
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();
CustomField cf1 = customFieldManager.getCustomFieldObjectByName("Technical Specialist");

def linkedIssue = issueLink.destinationObject.getCustomFieldValue(cf1);

}
}
return linkedIssue;

Give me simple code.

Thanks in advance.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 26, 2015

Your code is pretty close - the only problems I can see with it are more a question of checking what you're doing.  Either in the code or, when you use the "preview" option in the scripted field configuration, making sure that the issue you test with has all the right data.

  1.  Is your link type really named "Version"?
  2. Are you sure the link is outgoing and not incoming?
  3. Does your linked issue definitely have "Technical specialist" set to something?
  4. If you have more than one link of this type, you do know you are only going to get the value from one of them?
  5. You are returning "linkedIssue" back to the scripted-field for display, but the object you're getting might not actually be displayable.  Could you try "return linkedIssue.toString()"?

 

Muthu kader sahib March 26, 2015

Give me some sample code.One is issue(A) relates to another issue called (B).B having technical specialist value.I need that value in B issue in the view form.

Muthu kader sahib March 26, 2015

I may have multiple issue link to single issue.Kindly give me some piece of code

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 26, 2015

Your code is mostly fine, it just needs checking against the data, and the return statement needs a look to help you debug. As for the multiple links, there's two things you could do and you need to decide which it is: 1. You only want one result - decide on the rule that defines which one you want, and put that inside the loop, so that linkedIssue is set to the result and the loop ends 2. You want multiple results - convert linkedIssue into a list of results and instead of a single object def linkedIssue = [] (to get an empty list) ... linkedIssue.add (issueLink.destinationObject.getCustomFieldValue(cf1));

TAGS
AUG Leaders

Atlassian Community Events