setValue for one Attribute from object type during create object

meysam September 25, 2017

Hi
with this code get custom field value from select custom field jira:

customfield = customFieldManager.getCustomFieldObject("customfield_11303"); //select field
fieldval = issue.getCustomFieldValue(customfield); //CF type value is String

----------------------------------------------------------------
i want create object with this code:
https://documentation.riada.se/display/ICV49/Create+object

my problem is :

I have attribute that type is object. how can i add set value for this attribute in create script?
i tired read this doc:
https://insight-javadoc.riada.se/insight-javadoc-4.6/com/riadalabs/jira/plugins/insight/services/model/ObjectAttributeValueBean.html#setValue-com.riadalabs.jira.plugins.insight.services.model.ObjectTypeAttributeBean-java.lang.Object-

Please help me!

Best Regards

1 answer

1 accepted

1 vote
Answer accepted
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 26, 2017

Using setReferencedObjectBeanId from the mentioned API documentation you could to set the id for the Object to be used and it works.

Here is an example of a groovy code that sets a name of an object, and an object reference:


import com.atlassian.jira.component.ComponentAccessor;
import java.util.ArrayList;

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

/* The ID of the object type "Customer" is 1 in this example. The easiest way of finding the ID of an object type is to click at the object type in the object type tree and open up the web browser console to get the id that Insight uses to fetch objects. This will be easier to do in upcoming releases. */
def objectTypeCustomer = objectTypeFacade.loadObjectTypeBean(9320);

/* Create a new unsaved object bean */
def newObjectBean = objectTypeCustomer.createObjectBean();

/* Set up the attribute list */
def objectAttributeBeans = new ArrayList();

/* Set the name of the customer */
def nameObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(72882); // The ID of the object type attribute "Name"
def nameObjectAttributeBean = newObjectBean.createObjectAttributeBean(nameObjectTypeAttributeBean); // This is the name object attribute for the new object
def nameObjectAttributeValueBean = nameObjectAttributeBean.createObjectAttributeValueBean(); // This is the actual value of the attribute
nameObjectAttributeValueBean.setTextValueShort("Alexander"); // Set the name

def values = nameObjectAttributeBean.getObjectAttributeValueBeans();
values.add(nameObjectAttributeValueBean); // Add the value to the object attribute
nameObjectAttributeBean.setObjectAttributeValueBeans(values);

objectAttributeBeans.add(nameObjectAttributeBean); // Add to the list of object attributes

/* Set the referenced object */
def refObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(89849); // The ID for the referenced object type
refObjectAttributeBean = newObjectBean.createObjectAttributeBean(refObjectTypeAttributeBean);
refObjectAttributeValueBean = refObjectAttributeBean.createObjectAttributeValueBean(); // This is the actual value of the attribute
refObjectAttributeValueBean.setReferencedObjectBeanId(108766); // Set the ID

values = refObjectAttributeBean.getObjectAttributeValueBeans();
values.add(refObjectAttributeValueBean); // Add the value to the object attribute
refObjectAttributeBean.setObjectAttributeValueBeans(values);

objectAttributeBeans.add(refObjectAttributeBean); // Add to the list of object attributes

/* Set all object attributes to the object */
newObjectBean.setObjectAttributeBeans(objectAttributeBeans);

/* Store the object into Insight. The new ObjectBean will be updated with an unique ID */
try {
newObjectBean = objectFacade.storeObjectBean(newObjectBean);
log.warn("newObjectBean: " + newObjectBean);
} catch (Exception vie) {
log.warn("Could not create issue due to validation exception:" + vie.getMessage());
}

/* Done! :) */
return true;

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events