Adding multiple user groups to insight object using Groovy script

Carl Wiedebaum June 21, 2018

Hi, 

 

I have problem at hand where i need to use Insight automation and Groovy-script to make our asset management work. What i have in mind is that i have few Insight automation that checks for all objects that have empty group atribute and then add "Group1" to them. 

 

Heres the script so far: 

import com.atlassian.jira.component.ComponentAccessor;

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

Class objectAttributeBeanFactoryClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory");
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(objectAttributeBeanFactoryClass);


def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(162)


def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, objectTypeAttributeBean, 'group1');

objectTypeAttributeBean = objectFacade.storeObjectAttributeBean(newObjectAttributeBean);

 

It gets the job done, but while setting the group it overwrites the previous value - What i need it to do is to Add the group1 as second group. 

 

Another way to overcome this is if i can somehow input 2 different groups in newObjectAtributeBean - but that does not seem to work. So far i've tried following: 

def groups = ['group1', 'group2']
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, objectTypeAttributeBean, 'group1');
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, objectTypeAttributeBean, 'group1', 'group2');
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, objectTypeAttributeBean, 'group1, group2');
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, objectTypeAttributeBean, groups);

Whit out success... 

 

Any ideas? 

2 answers

0 votes
Richard Lange August 6, 2020

Any answers on this?

0 votes
pevana April 17, 2019

Hi Carl,

Have you ever found out how to do this? I am facing exactly the same issue...

Thanks,

Paul

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events