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

Scriptrunner. How to get the name of the object without its complete value

vpass May 20, 2022

Hi,

I use these functions to get an insight object in my script.

def incidentSiteId = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11401)
def incidentSiteValue = issue.getCustomFieldValue(incidentSiteId)

I get the complete value of the object :
>> [3507R+E CHASSIS, TWOWS-X2228-RJ45V+E, SU (CMDBXXXX-22574)]

But I would like to remove all unnecessary formatting
I use for the moment a regex to extract the name text.
I would like to get only the name of the object without bracket and without the CMDB ID.

off topic : if it can help, here is the regex I use :

def incidentAssetmatcher = incidentAssetValue =~ /.*\[(.*?)\(CMDBXXXX/
def incidentAssetResult = (incidentAssetmatcher) ? incidentAssetmatcher[0][1] : null

To optimize my script, is there a simple way like ".label" or ".name" to retrieve the name without full value and without regex ?

1 answer

0 votes
Matthew Clark
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.
May 25, 2022

Hi vpass

It looks like you are getting the value of an insight multi-select field, in which case the type returned should be List<ObjectBean> where the ObjectBean is `com.riadalabs.jira.plugins.insight.services.model.ObjectBean` documented here

This means you have access to the methods of that type for the elements in the returned list.
You can use the groovy expansion operator to build a new list of labels.
e.g:

 

import com.atlassian.jira.component.ComponentAccessor
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean

def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("TEST-1")
def field = ComponentAccessor.customFieldManager.getCustomFieldObjects().findByName('Insight Multiple')
def value = issue.getCustomFieldValue(field) as List<ObjectBean> //Multi-select insight field

if(value){
// * is the groovy spread operator
value*.getLabel()
}

try that in the script console for your insight field

 

Regards

Matthew

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events