Example Groovy script to update Object Type attribute value

Still need help?

The Atlassian Community is here for you.

Ask the community


The example Groovy script in this documentation allows to update object attributes with non-Object type attribute types, for example, Text type. In order to update an attribute of type Object type, the object key has to be used. 


Here's an example code snippet to reference an object with key "ITSM-2" to a Host object.

import com.atlassian.jira.component.ComponentAccessor;

def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade"));
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade"));
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory"));

def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(159).createMutable() //The id of the attribute

/* Create the new attribute bean based on the value */
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, objectTypeAttributeBean, "ITSM-2");
/* Load the attribute bean */
def objectAttributeBean = objectFacade.loadObjectAttributeBean(object.getId(), objectTypeAttributeBean.getId());
if (objectAttributeBean != null)

{ /* If attribute exist reuse the old id for the new attribute */ newObjectAttributeBean.setId(objectAttributeBean.getId()); }
/* Store the object attribute into Insight. */

{ objectTypeAttributeBean = objectFacade.storeObjectAttributeBean(newObjectAttributeBean); }
catch (Exception vie) {
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage());

DescriptionExample Groovy script to update Object type attribute
ProductJira Service Management, Insight - Asset Management
Last modified on Aug 12, 2021

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.