Forums

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

Simple script to update a custom field of a linked issue

Thomas Hardin
Contributor
April 1, 2020

Good day all,

By chance does anyone have a simple script to update a custom field of a linked issue with a specific outward link?

My scenario is this: We have Initiatives that are linked to 1 of 3 different issue types (Portfolio Epics, Program Epics or Epics). Each will be linked to the Initiative via the "Supports" issue link type. So, a Portfolio Epic "supports" an Initiative.

The goal is to have a listener that will update 1 custom field, "Health Status"(10596L) on the Initiative when the linked issue has been updated. 

I've seen multiple examples that support parent child relationships, but cannot seem to find a good example of one using the issue link type.

Any help is greatly appreciated.

1 answer

0 votes
Leo
Community Champion
April 2, 2020

Hi @Thomas Hardin,

There are 2 ways for this 

1. 

def LINK_NAME = "blocks"
def blockedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())?.findAll {it.issueLinkType.outward == LINK_NAME}

 2. if it's not working as expected you can go with 2nd method.

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

def changeHolder = new DefaultIssueChangeHolder();
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectByName("Field Name")
List allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(event.issue.getId());
for (Iterator outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
def linkType = issueLink.issueLinkType.name
if(linkType == "Cloners"){
def issue = issueLink.destinationObject
cField.updateValue(null,issue, new ModifiedValue(issue.getCustomFieldValue(cField),"Field value"),changeHolder)
}
}

 I've verified this in custom listener for Issue Updated event

Hope this helps

 

BR,

Leo

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events