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

script runner - Set field description not working for Insight field

Nagaraju October 18, 2022

Hi Team,

Recently I written a script to set field description as linked issues when selected issue from issue picker(Script runner issue picket field) but due to permission issue we are planning to change script runner picker field to JIRA insight field, but the same code not working for insight field.

Screenshot 2022-10-18 at 11.39.38 PM.png

 

 

 

Screenshot 2022-10-18 at 11.41.57 PM.png

Code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import groovy.transform.Field
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.issue.link.IssueLink;
import groovy.xml.MarkupBuilder
import java.sql.Timestamp

import groovy.transform.BaseScript


@BaseScript FieldBehaviours fieldBehaviours
@field ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser


def issueManager = ComponentAccessor.issueManager
def issueLinkManager = ComponentAccessor.issueLinkManager

// Related issue field name
final issueKey = getFieldById("customfield_38711");

// Relates issuelike
final issueLinkTypeName = 'Relates'

// Get the issue
def issue = issueManager.getIssueByCurrentKey(issueKey.getValue() as String)

def hIssueUrl = new StringBuffer()
def tableAppender = new StringBuffer()

def linkedIssuesHtmlLinks = filteredLinks.collect { issueLink ->
def issueUrl = "${baseUrl}/plugins/servlet/desk/portal/22/${issueLink.destinationObject.key}"

//Set field description
hIssueUrl.append("<br><a href='${issueUrl}'>${issueLink.destinationObject.key} - ${issueLink.destinationObject.summary} - ${issueLink.destinationObject.description} - ${(issueLink.destinationObject.status.getName().toString())} </a>")
}
issueKey.setDescription("Selected OCM Issue Feedback"+hIssueUrl)

2 answers

1 accepted

1 vote
Answer accepted
Max Lim _Adaptavist_
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.
October 20, 2022

The problem is that, since you are retrieving a value from an Insight field, you are getting an insight key, instead of an issue key.

So, you need to replace:

final issueKey = getFieldById("customfield_38711")

def issue = issueManager.getIssueByCurrentKey(issueKey.getValue() as String)

 with something like:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
@WithPlugin("com.riadalabs.jira.plugins.insight") def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade)
def insightObjectKey = getFieldById("customfield_38711").getValue() as String
// This should returns "OCM-3800 - Listing & Calendar Settings - Air Agile Calendar" def insightObjectLabel = objectFacade.loadObjectBean(insightObjectKey)?.label

def issueKey = (insightObjectLabel =~ /[A-Z]+-\d+/)[0]
def issue = issueManager.getIssueByCurrentKey(issueKey)

The snippet comes from this insight script documentation. Then, I improve it with our WithPlugin annotation to load autocomplete for classes when writing script. You can read more about ObjectFacade in its javadoc. Lastly, the "=~" is Groovy's find operator that match a substring using regex expression, which is documented here.

I hope this helps.

Nagaraju October 20, 2022

Hey @Max Lim _Adaptavist_ , Thanks for your help, it is working fine now.

-Musku

0 votes

Hi!

Olly here from Adaptavist Support!

May I ask, what version of ScriptRunner and Jira are you using?

Hope to hear from you soon!

Thanks,

Olly

Nagaraju October 19, 2022

HI @Olly von Fay-Siebenburgen _ScriptRunner_ , Thanks for your reply,

I am using JIRA Data/Center 8.20.11 and ScriptRunner 6.58.1

 

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events