how to create an attribute object in insight based on custom field Edited

I am trying to create an object based on an issue creation but I can not update an attribute based on custom field.

in fact updating attributes which are based on issue summary or issuekey, are successful but updating an attribute which is based on a text custom field is not succesful.

below is my scrip:

import com.atlassian.jira.component.ComponentAccessor;
import java.util.ArrayList;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ComponentManager.*
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.fields.CustomField.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.jira.user.ApplicationUser;



Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);

Class objectTypeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade");
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeFacadeClass);

Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade");
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass);

def objectTypeCustomer = objectTypeFacade.loadObjectTypeBean(111, null);

def newObjectBean = objectTypeCustomer.createObjectBean();

def objectAttributeBeans = new ArrayList();


/* Set the name of the AdvancePayment */
def nameObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(624);
def nameObjectAttributeBean = newObjectBean.createObjectAttributeBean(nameObjectTypeAttributeBean);
def nameObjectAttributeValueBean = nameObjectAttributeBean.createObjectAttributeValueBean();
nameObjectAttributeValueBean.setTextValueShort(issue.getSummary());

def values = nameObjectAttributeBean.getObjectAttributeValueBeans();
values.add(nameObjectAttributeValueBean);
nameObjectAttributeBean.setObjectAttributeValueBeans(values);

objectAttributeBeans.add(nameObjectAttributeBean);

 

/* Set the reporter of the AdvancePayment */
if (issue.getReporterUser() != null) {
def reporterObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(628);
def reporterObjectAttributeBean = newObjectBean.createObjectAttributeBean(reporterObjectTypeAttributeBean);
def reporterObjectAttributeValueBean = reporterObjectAttributeBean.createObjectAttributeValueBean();
reporterObjectAttributeValueBean.setTextValue(issue.getReporterUser().getName());

values = reporterObjectAttributeBean.getObjectAttributeValueBeans();
values.add(reporterObjectAttributeValueBean);
reporterObjectAttributeBean.setObjectAttributeValueBeans(values);

objectAttributeBeans.add(reporterObjectAttributeBean);
}

 

/* Set the Request Number of the AdvancePayment */
if (issue.getKey() != null) {

def keyObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(627);
def keyObjectAttributeBean = newObjectBean.createObjectAttributeBean(keyObjectTypeAttributeBean);
def keyObjectAttributeValueBean = keyObjectAttributeBean.createObjectAttributeValueBean();
keyObjectAttributeValueBean.setTextValue(issue.getKey());

values = keyObjectAttributeBean.getObjectAttributeValueBeans();
values.add(keyObjectAttributeValueBean);
keyObjectAttributeBean.setObjectAttributeValueBeans(values);

objectAttributeBeans.add(keyObjectAttributeBean);
}

 


def customFieldManager = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager()
def issueprogram = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_13085"))


if (issueprogram != null) {
def programObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(105089);
def programObjectAttributeBean = newObjectBean.createObjectAttributeBean(programObjectTypeAttributeBean);
def programObjectAttributeValueBean = programObjectAttributeBean.createObjectAttributeValueBean();
programObjectAttributeValueBean.setStringValue(issueprogram);

values = programObjectAttributeBean.getObjectAttributeValueBeans();
values.add(programObjectAttributeValueBean);
programObjectAttributeBean.setObjectAttributeValueBeans(values);

objectAttributeBeans.add(programObjectAttributeBean);
}



newObjectBean.setObjectAttributeBeans(objectAttributeBeans);

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;

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

536 views 3 19
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