Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,321
Community Members
 
Community Events
185
Community Groups

Read-Only custom Scripted field from Linked Issues

Edited
Heather Ronnebeck
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 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}"

1 answer

1 accepted

1 vote
Answer accepted
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 14, 2021 • edited

Ah, searching Google for: getLinkedIssuesByLinkTypeId cloud

Brought up, (of course) @Ravi Sagar _Sparxsys_ 's video on something related:

Now, that's a Post-function, but as you can see just through a little of the code, it's very different calls (having to talk to the API) to find linked issues. 

Because I was thinking - Scriptrunner on Cloud is very different from Server.

To wit:

Scriptrunner Server vs Cloud

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 15, 2021

Oh man, now you've done it. I went and learned the tiniest bit of Groovy on Jira Cloud:

def links = get('/rest/api/3/issue/' + issue.key)
.header('Content-Type', 'application/json')
.asObject(Map)

// issueType IDs can be found by inspecting HTML on the Issue Linking page: https://YOURSITE.atlassian.net/jira/settings/issues/issue-types

def issueTypeId_OutcomeDeliverable = "11101"

//Go through all inbound links and collect their keys if link is of specified type

def initiatives= []

links.body.fields.issuelinks*.inwardIssue.each{

if(it.fields.issuetype.id == issueTypeId_OutcomeDeliverable)
{
initiatives.add(it)
}

}

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

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

You'll want to make sure your Issue Type ID for Initiatives on your Cloud instance is 11101.

Thank goodness for @Ravi Sagar _Sparxsys_'s source code here, and this old script from @Aidan Derossett _Adaptavist_ that showed me I could do this in a simpler way without Lists, which I don't fully understand because I AM NOT A PROGRAMMER.

Anyways so yeah, that was some definition of fun. As I look at the final outcome though, I'm not quite sure what the point of this field is, since it replicates information in the Linked issues section:

Screen Shot 2021-10-15 at 2.09.50 AM.png

Like # people like this
Ravi Sagar _Sparxsys_
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.
Oct 15, 2021

:) I am glad it was useful.

Like Dave Rosenlund _Tempo_ likes this
Heather Ronnebeck
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 15, 2021

@Darryl Lee You need this field for sending the data to roadmapping tools and for listing as a column in Structure. That's the whole reason it was created in the first place. 

THANK YOU SO MUCH!!!!

Like Dave Rosenlund _Tempo_ likes this
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 15, 2021

Hrm. Does it actually work in Structure and whatever roadmapping tool you're using? My understanding was that Script Fields are a little... weird.

To wit:

In Cloud, Scripted Fields are not stored as normal Jira custom fields. Instead, the field output is added to an issue’s properties and therefore inherits the issue’s permissions. Scripted Fields are not currently searchable with JQL, but we’re working hard to make this available as soon as possible.

https://docs.adaptavist.com/sr4jc/latest/scriptrunner-migration/feature-parity

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events