Forums

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

Read-Only custom Scripted field from Linked Issues

Heather Ronnebeck
Community Champion
October 14, 2021

I am trying to create a scripted field in my cloud instance that looks up the Linked Issues for a specific link type and then outputs the key & summary into the field. 

Example. 

Epic TEST-12 is linked to ABC-123 using a "Initiative/Project" issue link. 

On ticket TEST-12 there is a field called "Initiative" and that field should show "ABC-123: Initiative XYZ" 

I had this working on server but now that I'm on a cloud instance I can't get the script to work with the changes between the plugins. 

Any help would be appreciated. Thank you!

 

Edit: This is the script from the server version of JIRA. Please note that this code DOES work in server. I am trying to convert it to Cloud.

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.label.LabelManager

import com.atlassian.jira.issue.Issue

import org.apache.log4j.*

// Configure logger

def log = Category.getInstance("com.domain.jira.automation")

log.setLevel(Level.DEBUG)

// log.debug "debug statements"

// Get necessary managers

def cfm = ComponentAccessor.customFieldManager

def issueManager = ComponentAccessor.issueManager

// Link Type IDs can be found by inspecting HTML on the Issue Linking page: https://jira.domain.com/secure/admin/ViewLinkTypes!default.jspa

def linkTypeId_OutcomeDeliverable = 11101

List<Issue> getLinkedIssuesByLinkTypeId(Issue issue, Long linkTypeId) {

//Go through all linked issues and collect their keys if link is of specified type

def linkManager = ComponentAccessor.issueLinkManager

List<Issue> foundIssues = []

linkManager.getInwardLinks(issue.id).each{

def linkedIssue = it.sourceObject

if (it.linkTypeId == linkTypeId)

{

foundIssues.add(linkedIssue)

}

}

log.debug "found "+(foundIssues.size())+" linked issues of that type"

foundIssues

}

def initiatives = getLinkedIssuesByLinkTypeId(issue, linkTypeId_OutcomeDeliverable)

def initiativeKeys = initiatives.collect { it.key }.join(', ')

def initiativeSummary = initiatives.collect { it.summary }.join(', ')

log.debug "found initiatives: ${initiativeKeys}"

return "${initiativeKeys}: ${initiativeSummary}"

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events