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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.