Set a default value for an Insight object attribute with type = select

Hello,

 

I try to set a default value for an Insight object attribute with type 'Select'.

I did an automation script which is launch when an object is created.

I used this script : https://documentation.riada.se/display/ICV49/Update+an+Object+Attribute and I have an error message because the ObjectAttributeValueBeans is null.

 

Can you help me ?

1 answer

0 votes

Hi Ludmilla,

Which version of Insight are you using? This documentation is for 4.x, we have documentation for 5.x at https://documentation.riada.se/insight/latest/insight-for-developers/groovy-scripting/groovy-script-examples/automation/update-an-object-attribute

The script does not work out of the box but need some fixes, in particular the ATTRIBUTE_NAME and VALUE needs to be replaced.

The scripts look really similar but has some importing changes according to the new API changes related to Insight 5.

Best Regards
Alexander

Hi,

Thank you for your answer. I have the version  5.1.4.

I applied your example but I have this error message :  AutomationRuleGroovyScriptAction, Unexpected error: Cannot invoke method getObjectAttributeValueBeans() on null object
java.lang.NullPointerException: Cannot invoke method getObjectAttributeValueBeans() on null object

 

This is my script :

import com.atlassian.jira.component.ComponentAccessor;
import com.amundi.jira.*
import conf.*

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

//Get the value of the 'Jira usage' field
def FlagAttribute = objectFacade.loadObjectAttributeBean(object.getId(), "Jira usage").createMutable()
log.error("FlagAttribute : " + FlagAttribute)
def newFlag = FlagAttribute.getObjectAttributeValueBeans()
log.error("newFlag : " + newFlag)

def valueFlag = FlagAttribute.createObjectAttributeValueBean()
valueFlag.setValue(objectTypeAttributeFacade.loadObjectTypeAttributeBean(FlagAttribute.getObjectTypeAttributeId()), "Servicedesk")
newFlag.clear()
newFlag.add(valueFlag);
FlagAttribute.setObjectAttributeValueBeans(newFlag)

/* Store the object Location into Insight. */
try {
FlagAttribute = objectFacade.storeObjectAttributeBean(FlagAttribute);
} catch (Exception vie) {
log.warn("Could not update attribute Jira usage due to validation exception:" + vie.getMessage());
}

Hi,

Could you please update to the latest version 5.2.7 as I know we fixed a bug related to this in 5.2.6
Let us know if the problem persists.

Best Regards
Alexander

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

412 views 0 3
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you