I'm trying to set attribute value "isInactive" to object.
But I keep getting this error when testing on Insight Script Console:
Cannot invoke method createMutable() on null object
Here is the code I am testing:
import com.atlassian.jira.component.ComponentAccessor;
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade");
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass);
def object = objectFacade.loadObjectBean("CI-47305");
int obj_id = object.getId()
def triageAttribute = objectFacade.loadObjectAttributeBean(obj_id, "Triage")
def mutableTriageAttribute = triageAttribute.createMutable();
def mutableTriageAttributeValues = mutableTriageAttribute.getObjectAttributeValueBeans()
def valueToAdd = mutableTriageAttribute.createObjectAttributeValueBean();
valueToAdd.setReferencedObjectBeanId(objectFacade.loadObjectBean("CI-79015").getId()) //isInactive
mutableTriageAttributeValues.add(valueToAdd);
mutableTriageAttribute.setObjectAttributeValueBeans(mutableTriageAttributeValues)
objectFacade.storeObjectAttributeBean(mutableTriageAttribute);
Try to add some logging to your script so you can see where things are breaking.
import com.atlassian.jira.component.ComponentAccessor;
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade);
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeAttributeFacade);
def object = objectFacade.loadObjectBean("CI-47305");
def inactiveObj = objectFacade.loadObjectBean("CI-79015")
def triageAttribute = objectFacade.loadObjectAttributeBean(object.id, "Triage")
log.info "atribute: ${triageAttribute}"
def mutableTriageAttribute = triageAttribute.createMutable();
log.info "mutable atribute: ${mutableTriageAttribute}"
def mutableTriageAttributeValues = mutableTriageAttribute.objectAttributeValueBeans
log.info "mutable atribute Values: ${mutableTriageAttributeValues}"
def valueToAdd = mutableTriageAttribute.createObjectAttributeValueBean();
valueToAdd.setReferencedObjectBeanId(inactiveObj.id)
mutableTriageAttributeValues.add(valueToAdd);
mutableTriageAttribute.setObjectAttributeValueBeans(mutableTriageAttributeValues)
objectFacade.storeObjectAttributeBean(mutableTriageAttribute)
BTW, for executing script within the context of insight, you don't need to load the classes the way you did, you should be able to just import them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.