Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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?
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
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes it should be available in all versions of Insight > 5.0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Removed double post
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.