How do I Automatically Assign Insight Object to Reporter (Jira User) on transition?

Tom Woodling November 20, 2017

I'd like to automatically assign an Insight object (selected using an Insight single-select custom field) to a Jira user when a Jira Service Desk Issue type is closed, using the value in the 'Reporter' field.  I'm fairly new to Jira automation and Groovy scripting, but even so I can't seem to find any examples of doing this - https://documentation.riada.se/display/ICV50/Update+object+attribute seems to be the closest, but it apparently relies on custom fields (which 'Reporter' is not, I believe).  Perhaps there is a better process I could follow?  Any suggestions would be gratefully received, or even a basic guide to taking a non-custom value from a JSD issue and using it to assign an attribute to an Insight object would be very helpful if anyone can point me to one...

Thanks,

Tom

1 answer

1 accepted

1 vote
Answer accepted
Alexander Sundström
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2017

Hi Tom,

You would need to create a groovy script for this. You should be able to get the reporters username in your groovy using issue.getReporterUser().getUsername() 

Which give you access to the User according to documentation at https://docs.atlassian.com/jira/7.2.2/com/atlassian/jira/user/ApplicationUser.html

As you have access to the issue, you also have access to the following methods: https://docs.atlassian.com/jira/7.2.2/com/atlassian/jira/issue/Issue.html

Using this, you should be able to assign the correct value in the mentioned groovy script. 

Best Regards
Alexander

Tom Woodling November 22, 2017

Hi Alexander,

Thanks so much for this info - it was exactly what I needed to assign the object to the reporter.  In case anyone else has this issue, all it took was a couple of simple modifications to the script at https://documentation.riada.se/display/ICV50/Update+object+attribute on lines 18 & 30:

 import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;

/* 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);

/* Get Insight Object Attribute Facade from plugin accessor */
Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade");
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass);


/* Get the factory that creates Insight Attributes */
Class objectAttributeBeanFactoryClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory");
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(objectAttributeBeanFactoryClass);

/* Grabs the username of the Reporter */
def userNameAdd = issue.getReporterUser().getUsername();

/* This is the custom field where the object/s you want to set the value */
CustomField insightCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(23456); // Change 23456 to the correct value
def insightObjects = issue.getCustomFieldValue(insightCustomField); // "issue" variable is always accessible in post function scripts.

/* This is the priority object type attribute and the one we want to modify */
def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(34567);

if (insightObjects != null) {
insightObjects.each{insightObject ->
/* Create the new attribute bean based on the value */
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(insightObject, objectTypeAttributeBean, userNameAdd);
/* Load the attribute bean */
def objectAttributeBean = objectFacade.loadObjectAttributeBean(insightObject.getId(), objectTypeAttributeBean.getId());
if (objectAttributeBean != null) {
/* If attribute exist reuse the old id for the new attribute */
newObjectAttributeBean.setId(objectAttributeBean.getId());
}
/* Store the object attribute into Insight. */
try {
objectAttributeBean = objectFacade.storeObjectAttributeBean(newObjectAttributeBean);
} catch (Exception vie) {
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage());
}
}
}



/* Done! :) */
return true;

 

Thanks again,

 

Tom 

Marçal_Martorell_i_Bou July 15, 2019

Is there any chance to apply this in JIRA cloud and insight for jira cloud?

Positive Thinking Company SA _Suisse_ September 17, 2019

Hi,

I'd like to do exactly the same , Initialise Insight Object to Reporter (Jira User) on create transition. The script seems OK but does not work... The insightObjects  is null. I check the ID of the object and is correct...

Could you please give the detailed configuration of Insight CF ?

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events