setValue for one Attribute from object type during create object

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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

237 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you