Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

GroovyInsightException: Cannot invoke method createMutable() on null object'

Jamil Rahimov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 20, 2022

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);

1.PNG2.PNG

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2022

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events