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}"
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
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
:) I am glad it was useful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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!!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.