Forums

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

Insight - update attrbute's value in a object

fjodors
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.
July 13, 2020

Hello


I am starting to investigate Insight plugin automation and I'd like to create groovy script to update object's attribute when other object was created/updated.

Could you help?

My scenario:
I have object LVVPN with ID 9
This object has attribute "user" with ID 313 , it could contains various users from another object "User". Currently it contains two users and I'd like to add one more.
I need to add user attribute value "fjodors.iljins" into object LVVPN

example.jpg

 

Based on this example https://documentation.mindville.com/display/INSSERV/Update+an+Object+Attribute I created script


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 lvVpnObject = objectFacade.loadObjectBean(9) //DM LV VPN - TH-9
def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(313).createMutable() //ID of user attribute in VPN object - 313

/* Create the new attribute bean based on the value */
//TH-21 this is User fjodors.iljins Object ID
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(lvVpnObject, objectTypeAttributeBean, 'TH-21');
/* Load the attribute bean */
def objectAttributeBean = objectFacade.loadObjectAttributeBean(lvVpnObject.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. */
try {
objectTypeAttributeBean = objectFacade.storeObjectAttributeBean(newObjectAttributeBean);
} catch (Exception vie) {
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage());
}

 

When I execute it from Insight Script console, it add 'fjodors.iljins' to LVVPN but other two users were removed!
I'd like to add one more user without removing users already added.
Could you help me understand how can I achieve this?

 

Thank you in advance.

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events