create nested object by script post function

meysam September 12, 2017

Hi

i need insight script for create object to my object scheme as following attachment file.

i'm very tired  reading this document :(

https://documentation.riada.se/display/ICV50/Insight+Post+Functions

how can i fix this?

screenshot.jpg

screenshot.jpg

3 answers

0 votes
Alexander Sundström
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.
September 22, 2017

Hi Meysam,

Perhaps this Groovy Script example for creating an object based on custom fields can be helpful. It's based in Insight 5, https://documentation.riada.se/display/ICV50/Create+object

There is more examples available that can be used as an inspiration at https://documentation.riada.se/display/ICV50/Groovy+script+examples

Also, We have some Partners at Riada (Developer of Insight), that can help you with your configuration if needed and creating such scripts. Let us know if that is the case.

Best Regards
Alexander

Ola_Melin
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.
September 22, 2017

Here is an template that can be used to see the principle of the 

import com.atlassian.jira.component.ComponentAccessor;
import java.util.ArrayList;
import com.atlassian.jira.issue.fields.CustomField;

/* Get Insight Object Facade from plugin accessor */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);

/* Get Insight Object Type Facade from plugin accessor */
Class objectTypeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade");
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeFacadeClass);

/* Get Insight Object Attribute Facade from plugin accessor */
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);

CustomField jiraCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10201);
CustomField modelNameCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10200);

/* The object schema to use */
def objectSchemaId = 61;
def cpuType;
/* get value from cascading field */
def cpuTypeValue = jiraCustomField.getValue(issue);
if (cpuTypeValue != null) {

/* Find the object type based on input value */
for (objectType in objectTypeFacade.findObjectTypeBeansFlat(objectSchemaId)) {

if (objectType.name.equalsIgnoreCase(cpuTypeValue.values()[1].toString())) {
cpuType = objectType;
break;
}
}
/* Create a new unsaved object bean */
def newObjectBean = cpuType.createMutableObjectBean();
def objectAttributeBeans = new ArrayList();
/* Load the attribute from the cpu object type */
def nameObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(cpuType.id, "Name");
objectAttributeBeans.add(objectAttributeBeanFactory.createObjectAttributeBeanForObject(newObjectBean, nameObjectTypeAttributeBean, modelNameCF.getValue(issue)));
/* Set all object attributes to the object */
newObjectBean.setObjectAttributeBeans(objectAttributeBeans);
newObjectBean = objectFacade.storeObjectBean(newObjectBean);

log.warn("Created object bean " + newObjectBean.objectKey);
}



/* Done! :) */
return true;
Filip Håkansson November 2, 2017

Does "com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory" still exist?


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

 It gives  ClassNotFoundException...

Ola_Melin
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.
November 2, 2017

Yes it should be available in all versions of Insight > 5.0

Filip Håkansson November 2, 2017

thanks, my misstake :)

Volker Albrich January 6, 2018

Hi, where do I get the correct values for 10201 and 10200??

CustomField jiraCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10201);
CustomField modelNameCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10200);

 Thanks in advance and sorry for the dumb question, but I'm completely new...

Volker Albrich January 6, 2018

I get error:

class com.riadalabs.jira.plugins.insight.common.exception.GroovyInsightException

GroovyInsightException: No signature of method: java.util.ArrayList.values() is applicable for argument types: () values: [] Possible solutions: plus(java.util.Collection), plus(java.lang.Object), plus(java.lang.Object), plus(java.lang.Object), plus(java.util.Collection), plus(java.lang.Iterable)'

 

What am I doing wrong?

0 votes
Ola_Melin
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.
September 20, 2017

Removed double post

0 votes
Ola_Melin
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.
September 20, 2017

Hi, 

You can use this Groovy script as a template and see how it can be done. 

It only contains 2 custom fields but this will show you the principle.

 

import com.atlassian.jira.component.ComponentAccessor;
import java.util.ArrayList;
import com.atlassian.jira.issue.fields.CustomField;

/* Get Insight Object Facade from plugin accessor */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);

/* Get Insight Object Type Facade from plugin accessor */
Class objectTypeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade");
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeFacadeClass);

/* Get Insight Object Attribute Facade from plugin accessor */
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);

CustomField jiraCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10201);
CustomField modelNameCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10200);

/* The object schema to use */
def objectSchemaId = 61;
def cpuType;
/* get value from cascading field */
def cpuTypeValue = jiraCustomField.getValue(issue);
if (cpuTypeValue != null) {

/* Find the object type based on input value */
for (objectType in objectTypeFacade.findObjectTypeBeansFlat(objectSchemaId)) {

if (objectType.name.equalsIgnoreCase(cpuTypeValue.values()[1].toString())) {
cpuType = objectType;
break;
}
}
/* Create a new unsaved object bean */
def newObjectBean = cpuType.createMutableObjectBean();
def objectAttributeBeans = new ArrayList();
/* Load the attribute from the cpu object type */
def nameObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(cpuType.id, "Name");
objectAttributeBeans.add(objectAttributeBeanFactory.createObjectAttributeBeanForObject(newObjectBean, nameObjectTypeAttributeBean, modelNameCF.getValue(issue)));
/* Set all object attributes to the object */
newObjectBean.setObjectAttributeBeans(objectAttributeBeans);
newObjectBean = objectFacade.storeObjectBean(newObjectBean);

log.warn("Created object bean " + newObjectBean.objectKey);
}



/* Done! :) */
return true;

 

Cheers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events