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

mozhde.a August 16, 2017

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
TAGS
AUG Leaders

Atlassian Community Events