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)

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 23, 2022

Hi @Nagaraju

I have done a basic test in my environment, and I can get the description to display correctly.

Below is the sample Server-Side Behaviour code that I have used to test:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleInsight = getFieldById(fieldChanged)
def sampleInsightValue = sampleInsight.value?.toString()

sampleInsight.description = ''

if (sampleInsightValue) {
sampleInsight.description = sampleInsightValue
}

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications

Below is a screenshot of the Behaviour configuration:-

image1.png

 

Below are a couple of test screenshots for your reference:-

If you observe the screenshots below, the description for the Insight field is loading as expected.

test1.png

 

test2.png

 

Please note that I have tested this with the latest release of ScriptRunner, i.e. version 7.3.0. If you are using an older version, upgrading it to the latest release would be best.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events