Forums

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

How to remove only link types from Epic Links in Scriptrunner?

박성우 January 25, 2024

Hi.

I used CustomField in ScriptRunner to create a field to view the Assignee of the LinkedIssue.

I want to exclude the Assignee of EpicLink, Sub-task from this, but I'm not sure how.

If you can tell me how to do this, I would be very grateful.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()

def linkedAssignees = []

def allLinks = issueLinkManager.getOutwardLinks(issue.id) + issueLinkManager.getInwardLinks(issue.id)

allLinks.each { IssueLink issueLink ->
def linkedIssue = issueManager.getIssueObject(issueLink.sourceId ?: issueLink.destinationId)
if (linkedIssue.assignee) {
linkedAssignees.add(linkedIssue.assignee)
}
}

linkedAssignees = linkedAssignees.unique()

return linkedAssignees

 

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
January 26, 2024

Hi @박성우

In your description, you mentioned:-

I used CustomField in ScriptRunner to create a field to view the Assignee of the LinkedIssue.

I want to exclude the Assignee of EpicLink, Sub-task from this, but I'm not sure how.

If you can tell me how to do this, I would be very grateful.

Please clarify what do you mean by excluding Assignee of Epic Link, Sub-task.

Do you mean you want to exclude Assignees of an Epic and Assignees of Sub-Tasks?

Thank you and Kind regards,

Ram

박성우 January 26, 2024

Thanks.

After applying the above script, not only the assignee of the LinkedIssue is displayed, but also the assignee of the EpicLink and the assignee of the Sub-task.

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
February 6, 2024

Hi @박성우

Sorry for the late response. I've been very busy these past few weeks.


Below is a sample working code for your reference:-
import com.adaptavist.hapi.jira.issues.Issues

def issue = Issues.getByKey('MOCK-1')
def assignees = [] as ArrayList<String>

issue.getOutwardLinks { excludeSystemLinks = false }.each { issueLink ->
def targetIssue = issueLink.destinationObject

if ( !(targetIssue.issueType.name in ['Epic', 'Sub-task']) ) {
assignees << targetIssue.assignee.name
}
}

assignees.unique()

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

I have run this example on the ScriptRunner Console, hence you will need to modify it according to the ScriptRunner feature you are using.

Also, I have used ScriptRunner's HAPI feature to simplify the code.

Below is a screenshot of the ScriptRunner Console for your reference:-

console.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer