Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

I'm trying to get some attributes from an object and save them to different variables, yet I keep getting this error when testing on Insight Script Console:

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

I add the object key to the "Object Key" field but it still sees it as a null object. Does this have to do with my code or does Insight not recognize the key I have inserted?

Here is the code I am testing:

import groovy.json.*
import com.atlassian.jira.issue.*
import com.atlassian.jira.component.ComponentAccessor
import org.joda.time.format.*
import java.lang.String
import java.text.SimpleDateFormat
import org.apache.log4j.*

//Inicialize object & object attributes
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass(""));
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass(""))
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass(""));

//Load object attributes
def key = objectFacade.loadObjectAttributeBean(object.getId(), 1448).getObjectAttributeValueBeans()[0].getValue(); //The id of the attribute
def name = objectFacade.loadObjectAttributeBean(object.getId(), 1449).getObjectAttributeValueBeans()[0].getValue();
def ti = objectFacade.loadObjectAttributeBean(object.getId(), 1463).getObjectAttributeValueBeans()[0].getValue();
def ta = objectFacade.loadObjectAttributeBean(object.getId(), 1464).getObjectAttributeValueBeans()[0].getValue();
def loc = objectFacade.loadObjectAttributeBean(object.getId(), 3981).getObjectAttributeValueBeans()[0].getValue();
def dinc = objectFacade.loadObjectAttributeBean(object.getId(), 4002).getObjectAttributeValueBeans()[0].getValue();
def dfim = objectFacade.loadObjectAttributeBean(object.getId(), 4003).getObjectAttributeValueBeans()[0].getValue();
def org = objectFacade.loadObjectAttributeBean(object.getId(), 4063).getObjectAttributeValueBeans()[0].getValue();
def notes = objectFacade.loadObjectAttributeBean(object.getId(), 4066).getObjectAttributeValueBeans()[0].getValue();

return key;

1 answer

0 votes

Try comment out all but one of your "load object attributes" line then test them all one by one.

I suspect that either one of the attribute id is incorrect, or (most likely), the object key you entered doesn't have a value for one of those attributes.

When the object has an empty attribute, the "loadObjectAttributeBean" method will return a null value and you can't call getObjectAttributeValueBeans on an attribute without any values.

So you'll need to split each line into 2 statements, first, get the attributeBean ... and if it's non-null, then get its values (or as your example, its first value).


Instead of 

def ti = objectFacade.loadObjectAttributeBean(object.getId(), 1463).getObjectAttributeValueBeans()[0].getValue();


def tiOAB = objectFacade.loadObjectAttributeBean(object.getId(), 1463)
def ti = tiOAB ? toPAB.objectAttributeValueBeans[0].value : null

Or, for a more complete approach to get all the attributes for an object (without hardcoding all its attribute id):

import com.atlassian.jira.component.ComponentAccessor

def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade);
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeAttributeFacade);
def configureFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ConfigureFacade);

def attributeMap = object.objectAttributeBeans.collectEntries { objAttr ->
def attribute = objectTypeAttributeFacade.loadObjectTypeAttribute(objAttr.objectTypeAttributeId)
def attributeName =
def isMulti = attribute.maximumCardinality != 1
def attributeValue = ''
switch (attribute.type) {
case ObjectTypeAttributeBean.Type.REFERENCED_OBJECT:
attributeValue = objAttr.objectAttributeValueBeans.collect { objectFacade.loadObjectBean(it.referencedObjectBeanId).label }
case ObjectTypeAttributeBean.Type.STATUS:
attributeValue = objAttr.objectAttributeValueBeans.collect { configureFacade.loadStatusTypeBean(it.value as Integer).name }
case ObjectTypeAttributeBean.Type.USER:
attributeValue = objAttr.objectAttributeValueBeans.value.collect{ComponentAccessor.userManager.getUserByKey(it as String).name}
case ObjectTypeAttributeBean.Type.PROJECT:
attributeValue = objAttr.objectAttributeValueBeans.value.collect{ComponentAccessor.projectManager.getProjectObj(it as Long).key}
default: //DEFAULT/GROUP
attributeValue = objAttr.objectAttributeValueBeans.value
if(!isMulti && attributeValue instanceof List){
attributeValue = attributeValue [0]
[(attributeName ): attributeValue ]

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

JSM Jira Automation: How to Send SLA Breached Notifications

Hi Everyone, In   this tutorial,  we will show you how you can monitor an SLA, and send notifications before or after the SLA has been breached.   SLA Threshold Trigger The SLA t...

610 views 5 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you