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

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

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

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 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas 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...

366 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you