Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,977
Community Members
 
Community Events
165
Community Groups

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

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

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
Community showcase
Published in Jira Service Management

Coming Soon: Insight Changing to Assets

The 2020 acquisition of Mindville added powerful asset and configuration management capabilities to Jira Service Management in the form of Insight. Following the completion of that integration, custo...

466 views 3 13
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you