The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

vpass
Contributor
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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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 Champions.
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

DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events