It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

setValue for one Attribute from object type during create object

meysam Sep 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 Sep 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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

454 views 0 4
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you