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
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.
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