Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,367,520
Community Members
 
Community Events
168
Community Groups

Updating a custom field with an Insight Object attribute value during Issue Update event

Edited

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. 

1 answer

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.

Like # people like this

Hallo Thomas,

any news?

 

Thanks

 

Christian

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events