It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Tom Woodling Nov 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 Nov 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 Nov 22, 2017 • edited

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

486 views 0 4
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you