Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

copy linktype value to a custom field

maarten breesnee
Contributor
April 9, 2019

users want to order (so not filter) on a linktype. We want to have script in place that copies the value of the linktype ones it transitions into a custom field so we can use that for ordering.

 

is that possible?

 

1 answer

0 votes
Antoine Berry
Community Champion
April 9, 2019

Hi,

I guess you can use the "IssueLinkCreatedEvent" and adapt this script to your needs : 

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;

List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) {
IssueLink issueLink = (IssueLink) inIterator.next();
def linkedIssue = issueLink.getSourceObject()
def linkedIssueTypeName = issueLink.getIssueLinkType().getName()

log.debug("issueLink : " +linkedIssueTypeName
log.debug("linkedIssue : " + linkedIssue)

int cfId = 11001
def cf = customFieldManager.getCustomFieldObject(cfId)
def cfValue = issue.getCustomFieldValue(cf)
cf.updateValue(null, issue, new ModifiedValue(cfValue, linkedIssueTypeName), new DefaultIssueChangeHolder())
}

You can get the outward links similarly.

Antoine

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events