setValue for one Attribute from object type during create object

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:

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:

Please help me!

Best Regards

1 answer

1 accepted

1 vote
Answer accepted

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("");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);

/* Get Insight Object Type Facade from plugin accessor */
Class objectTypeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeFacadeClass);

/* Get Insight Object Attribute Facade from plugin accessor */
Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
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

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

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

/* Set all object attributes to the object */

/* 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
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


275 views 0 7
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