Forums

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

Scripted field value based on any issue link to a certain project

Jeff Tillett
Community Champion
March 3, 2020

I am attempting to write a scripted field in ScriptRunner that will return a value of "Yes" or "No" based on whether or not a given issue has any link relationships to any issues in a specific project.

For example, I can find these issues in JQL by running the query: issueFunction in linkedIssuesOf("project = MYPROJECT")

So now what I want to do, is return a value of "Yes" for a scripted field on all issues matching this condition.

Most of what I'm reading is talking about inward or outward links, or links of a certain type, and my links could be inward OR outward, and could be any relationship. I just need this field to tell me whether or not the issue has a linked issue in MYPROJECT for reporting purposes.

If anyone has any example code, I'm kind of stuck at where to even start since I am not looking for a specific type of link.

1 answer

1 accepted

1 vote
Answer accepted
PD Sheehan
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.
March 3, 2020

Hi @Jeff Tillett 

If you don't need to bother with the link directionally, you get just use the 'getAllIssues()' method from the linkCollection. 

Here is a snippet that works in the console:

import com.atlassian.jira.component.ComponentAccessor

def ilm = ComponentAccessor.issueLinkManager
def im = ComponentAccessor.issueManager

def issue = im.getIssueObject('JSP-1922') //for console only, issue is included in the context for scripted fields
def projectKeyToFlagLinks = 'JSP'
ilm.getLinkCollectionOverrideSecurity(issue).any{
projectKeyToFlagLinks in it.allIssues.project.key
}

This returns a boolean true/false is the projectKeyToFlagLinks is included in any of the links in the collection.

In this example, I used getLinkCollectionOverriteSecurity(issue)... this means that it will return true even when the current user can't even see the project in question. If that matters to you, then you'll need to use getLinkCollection(issue, currentUser) .

Hope that helps.

Suggest an answer

Log in or Sign up to answer