How to copy components from linked issues to the trigger issue in Jira Automation?

Gisela Lassahn
Contributor
July 15, 2024

Hello all together,

I'm in Jira Datacenter 9.4.8 running Automation for Jira version 9.1.1 and ScriptRunner version 8.29.0. 

Within a manually triggered automation rule I need a groovy script to add the components of some linked issues to the trigger issue.

I've tried many ways, but there seems to be no way to do the add. 
I've found some ways where I didn't get any error, but the components were not added.
This is one of my variants for you to understand what I'm trying to do:

 

import com.atlassian.jira.component.ComponentAccessor

def linkedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())?.findAll

                     {it.issueLinkType.inward == "Ticket enthalten in Softwarefreigabe / Issue included in Software Approval"}

def linkedIssue = null;

def comp = null;

for (int i = 0; i < linkedIssues.size(); i++) {

    linkedIssue = linkedIssues[i].destinationObject

    comp = linkedIssue.getComponents()

    issue.components.addAll(comp)

}
Do you have a really tested solution for me?

comp.size() was 1 in my example, and both issues (trigger issue and linked issue with one component) are in the same project.

I've found no solution to do the task without a groovy script, (only with automation) either.

Best regards,
Gisela

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Jim Knepley - ReleaseTEAM
Atlassian Partner
July 15, 2024

I think you have a problem with how you're testing for the issue link type.

getOutwardLinks returns a list of IssueLink objects, and you're trying to fid those issues of a particular link type by looking at the .inward attribute, which I don't think exists.

The link type is available via the getIssueLinkType method, which returns an IssueLinkType.

I also prefer using .each to iterate lists, so you'll end up with something more like this:

import com.atlassian.jira.component.ComponentAccessor


def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def linkedIssues = issueLinkManager.getOutwardLinks(issue.getId())?.findAll {
it.getIssueLinkType().getInward() == "Ticket enthalten in Softwarefreigabe / Issue included in Software Approval"
}

if (linkedIssues) {
linkedIssues.each { link ->
def linkedIssue = link.destinationObject
def components = linkedIssue.getComponents()

if (components) {
issue.components.addAll(components)
}
}
}

 

This is completely untested, no guarantees of anything.

Gisela Lassahn
Contributor
July 16, 2024

Unfortunately your script doesn't bring any error (like mine) but does not have any effect on the issue (like mine).

TAGS
AUG Leaders

Atlassian Community Events