I keep on telling myself that there has to be an easy way to do this, but try as I can I can't find it. Anyhow, here goes;
I have an object called Simulator, this has around 50 attributes, most made up of objects. One of these attributes is also an object called Aircraft. I simply want to return this value. I have tried to create an Insight Object with the following config
Multiple: false
Object Schema: Example CMDB
Filter Scope (IQL): objectType = "Aircraft"
Filter Issue Scope (IQL): Simulator = ${CMDB Simulator}
But this returns nothing.
I have also tried to return this as a Java Script field which I managed to pull from an earlier request and changed
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Level
log.setLevel(Level.INFO)
Issue issue = issue
def simField = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('CMDB Simulator'))
if(simField){
def commentManager = ComponentAccessor.getCommentManager()
def sdUser = ComponentAccessor.getUserManager().getUserByName('robotuser');
//insight classes & components
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade");
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass);
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
ArrayList <String> userList = new ArrayList<String>();
for(Simulator in simField){
//extract insight key ang get object
def sim=Simulator.toString()
log.info(sim)
def simKey = sim.substring(sim.indexOf('(')+1,sim.indexOf(')'))
def simObject = objectFacade.loadObjectBean(simKey)
//get Aircraft for that Simulator
def aircraft = objectFacade.loadObjectAttributeBean(simObject.getId(), "Aircraft").getObjectAttributeValueBeans()
if(aircraft) {
log.info(aircraft[0])
def aircraftString = aircraft[0].toString()
log.info(aircraftString)
return aircraftString
}
}
log.info(aircraft + "returned!")
}
This script returns the following log messages
2021-07-16 13:01:31,427 INFO [runner.ScriptBindingsManager]: A320n29 - S35 (CMDB-276)
2021-07-16 13:01:31,427 INFO [runner.ScriptBindingsManager]: [1912(287)]
2021-07-16 13:01:31,427 INFO [runner.ScriptBindingsManager]: [1912(287)]
How can I change [1912(287)] into the value?
Which seems to be half way there, but as I say I would hope the process is a lot easier than this.
Any pointers?