It's not the same without you
Join the community to find out what other Atlassian users are discussing, debating and creating.
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;
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.
Read moreAtlas 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...
Connect with like-minded Atlassian users at free events near you!
Find a groupConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.
Start an AUGYou're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs