Automation link script

Fadi Shahwan November 19, 2024

Hi Everyone, 

I'm working on creating an automation role that links the current issue with another issue in an issue picker field. I'm using the below script however I'm not sure what is the issue. can you support ?

 

 ,,,,

 

import com.atlassian.jira.issue.Issue
def issuePickerField = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Budget"))

if (issuePickerField) {
    issuePickerField.each { selectedIssue ->
        def issueKeyToLink = selectedIssue.getKey() // Use getKey() method to get the issue key
        def issueLinkManager = ComponentAccessor.getIssueLinkManager()
        issueLinkManager.createIssueLink(issue.id, selectedIssue.id, 10000, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()) // Replace 10000 with your link type ID
    }
}
,,,,,,,,,

1 answer

1 accepted

1 vote
Answer accepted
Kseniia Trushnikova
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 20, 2024

Hi @Fadi Shahwan,

Jira does not have the issue picker type of fields natively. Do you have an add-on installed that provides these types of fields?

Fadi Shahwan November 20, 2024

Hi Kseniia,

Yes, I think it is one of scriprunner fields 

Kseniia Trushnikova
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 20, 2024

 @Fadi Shahwan, try this:

import com.atlassian.jira.component.ComponentAccessor 
def issuePickerField = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Single Issue Picker"))
def linkedIssueKey = Issues.getByKey(issuePickerField.key)
if (issuePickerField) {
issue.link('relates', linkedIssueKey)
}

You can use the method link() as it's shown in the example in Adaptivist library: https://library.adaptavist.com/entity/search-and-link-issues

Fadi Shahwan November 20, 2024

Many Thanks Kseniia, it is working ;) 

Like Kseniia Trushnikova likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22.2
TAGS
AUG Leaders

Atlassian Community Events