You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello all,
I am trying to set a custom listener up that will take attribute values of an Insight Object and populate the custom fields when an issue is updated, just like the post function. I've found a few examples out there, but have basically drawn a blank here.
I started with this script from Riada:
import
com.atlassian.jira.component.ComponentAccessor;
import
com.atlassian.jira.issue.fields.CustomField;
import
com.atlassian.jira.issue.Issue;
import
com.atlassian.jira.issue.MutableIssue;
import
com.atlassian.jira.event.type.EventDispatchOption;
import
com.atlassian.jira.issue.context.IssueContextImpl;
import
com.atlassian.jira.issue.fields.config.FieldConfig;
/* Custom field for the organisation */
CustomField organisationCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(
10000
);
if
(organisationCF ==
null
|| organisationCF.getValue(issue) ==
null
) {
return
false
;
}
/* 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);
Class customFieldFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass(
"com.riadalabs.jira.plugins.insight.services.core.CustomFieldService"
);
def customFieldFacade = ComponentAccessor.getOSGiComponentInstanceOfType(customFieldFacadeClass);
IssueContextImpl issueContext =
new
IssueContextImpl(issue.getProjectObject(), issue.getIssueType());
FieldConfig fieldConfig = organisationCF.getRelevantConfig(issueContext);
def objectTypeAttributeName =
null
;
//objectTypeAttributeName = "JIRA User" // Set an object type attribute name if you want to restrict the user fetch on just that type attribute.
def objects = customFieldFacade.findUserObjectsByNormalCustomField(
fieldConfig.getId(), currentUser,
objectTypeAttributeName,
issue.getProjectObject().getId())
if
(objects.isEmpty()) {
return
false
;
}
def organisationTypeAttributeId =
123
;
// The object type attribute id of the organisation attribute for the user object type.
def organisationObjectAttributeBean = objectFacade.loadObjectAttributeBean(objects[
0
].getId(), organisationTypeAttributeId);
if
(organisationObjectAttributeBean ==
null
) {
return
false
;
}
MutableIssue mi = (MutableIssue) issue;
mi.setCustomFieldValue(organisationCF, [objectFacade.loadObjectBean(organisationObjectAttributeBean.getObjectAttributeValueBeans()[
0
].getReferencedObjectBeanId())]);
ComponentAccessor.getIssueManager().updateIssue(currentUser, mi, EventDispatchOption.DO_NOT_DISPATCH,
false
);
/* We are done! */
return
true
;
All I want to do is take the attribute values and populate the custom fields.
Any help is greatly appreciated.
Hi
Did you come right with this ?
I am trying to do something similar.
I have "reporter details" object in Insights.
Attributes Department and Business Unit.
I want to update Jira custom fields "Business Unit" and "Department" on all tickets to the attributes above.
I would like this to do this with Automation, so that any changes are taken into account.
I can do it in the workflow on new issues, but need to update these fields for all pre-existing.
Help Please
Unfortunately, I have not been successful. I'm still working on it, but keep getting pulled away for other priorities. I have a scripting expert on my team now and hope that he may be able to work some magic. I'll keep you updated with our progress.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.