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 ?
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.