When I click on create question, in the new page I can't type texte in the box "What do you want to know?".
What you are getting is an ArrayList of "objectBean" objects. In your case, there is a single value in that list.
The array list and the object bean happen to have some default string representation that causes the output to look like "[Alabama (IAS-575858)]"
If the attribute you want happens to be the Label (or if you're only interested in the key)you can get either with something like this:
import com.atlassian.jira.component.ComponentAccessor
def im = ComponentAccessor.issueManager
def issue = im.getIssueObject("IPT-88")
def customFieldManager = ComponentAccessor.gcustomFieldManager
def stateCf= customFieldManager.getCustomFieldObject("customfield_15500")
def cfValue = issue.getCustomFieldValue(stateCf)
def stateObject = cfValue[0]
def objectLabel = stateObject.label
def objectKey = stateObject.objectKey
But if you want to retrieve a value for a specific attribute (that isn't the label), then it gets a bit more complicated.
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
@WithPlugin('com.riadalabs.jira.plugins.insight')
@PluginModule ObjectTypeFacade objectTypeFacade
@PluginModule ObjectTypeAttributeFacade objectTypeAttributeFacade
def im = ComponentAccessor.issueManager
def issue = im.getIssueObject("IPT-88")
def customFieldManager = ComponentAccessor.gcustomFieldManager
def stateCf= customFieldManager.getCustomFieldObject("customfield_15500")
def cfValue = issue.getCustomFieldValue(stateCf)
def stateObject = cfValue[0]
def attributeName = "State Name"
def objectType = objectTypeFacade.loadObjectType(stateObject.objectTypeId)
def attributeBean = objectTypeAttributeFacade.findObjectTypeAttributeBeans(objectType.id).find{ it.name == attributeName}
def attributeValues = stateObject.objectAttributeBeans.find{it.objectTypeAttributeId == attributeBean.id}?.objectAttributeValueBeans*.value
//all attribtutes are stored as list, even when max cardinality = 1
//so we get the first one here
if(attributeValues){
def stateName = attributeValues[0]
}
I wrote an article with some examples: https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Interacting-with-Insight-objects-from-Scriptrunner-Server-Data/ba-p/1649857
This shows how it can be simplified with a utility class.
Thanks for your help! This is exactly what I was looking for and is far more reliable then the substring manipulation I was going to do instead haha.
Based on the things shown here I can actually put it all into one degenerate line of code.
def USState = (issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15500"))).label[0]
I'm not trying to call attributes other then the label at present, but I'm bookmarking this post in case I do later and will definitely take a look at your guide if that happens.
Once again thanks a million for your assistance here!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.