Groovy script to determine project for linked issue

Richard Gianattasio
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 29, 2020

Using the solution found here: https://community.atlassian.com/t5/Answers-Developer-Questions/Check-if-linked-issue-is-in-a-certain-project/qaq-p/564203

I have added the below groovy script to the Set Field Value of Related Issues Post-function being used in my workflow so that I can conditionally execute the function when the Linked issue is in a specific project.   

Here is the script: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def io = ComponentAccessor.getIssueManager().getIssueObject(issueObject.getKey())
def issueLinkManager = ComponentAccessor.getIssueLinkManager()

issueLinkManager.getOutwardLinks(io.id).any{it.destinationObject.getProjectObject().getKey() == 'S1S2'}

What I am finding is that the array is always null, so the last line will always be false.

It is properly resolving the issue, but the linked issue is not resolving.

When i change the last line to getInwardLinks I get a non-null array, but the information does not look correct and still resolves as false.

My issue has an "addresses" link.

1 answer

0 votes
Radhika Vijji _Innovalog_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2020

Hi Richard,

With the simplified API of JMWE, your script can be much simpler. 

relatedIssue?.project?.key == "S1S2"

relatedIssue here refers the related/linked issue being processed by the post-function, in turn. 

Regards,

Radhika

Suggest an answer

Log in or Sign up to answer