Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to store object attribute values and trigger only one update event (insight automation)?

Marina Veselić April 22, 2022

Hi!

Here is an example of changing and storing an attribute bean of an insight object: [Example Groovy script to update Object Type attribute value|https://confluence.atlassian.com/jirakb/example-groovy-script-to-update-object-type-attribute-value-1077910497.html]. I extended that example to store three attribute values. I use it in an automation script. Let's name it 'A' and it is triggered on a Move event.

try{
objectBeansToStore.each{objAttBean ->
objectTypeAttributeBean = objectFacade.storeObjectAttributeBean(objAttBean);
}
objectBeansToDelete.each{
objectAttributeBean = objectFacade.deleteObjectAttributeBean(objAttBean.id);
}
} catch (Exception e){
log.error("Could not update object attribute due to validation exception:" + e.getMessage());
}

The problem is that each store triggers an Insight update object event, three in total. That is a problem since I have automations that are triggered on an Object updated event. And when I move hundreds of objects, the other automations multiply by three.

Is there a way to store any number of attributes and their new values to produce only one update event? I looked through the API to see if there is a function that takes a list of Object attributes to update but cannot find any. I'm sorry if I didn't look hard enough and missed something.

I have Jira 8.13.18 and Insight plugin v 8.9.4.

Thanks for the help!

Cheers, 
Marina

2 answers

1 accepted

2 votes
Answer accepted
PD Sheehan
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.
April 22, 2022

First off, did you know that you can suppress events altogether?

Instead of 

objectTypeAttributeBean = objectFacade.storeObjectAttributeBean(objAttBean)
//or
objectAttributeBean = objectFacade.deleteObjectAttributeBean(objAttBean.id)

You can do

import static com.riadalabs.jira.plugins.insight.services.events.EventDispatchOption.DO_NOT_DISPATCH

objectTypeAttributeBean = objectFacade.storeObjectAttributeBean(objAttBean, DO_NOT_DISPATCH)
//or
objectAttributeBean = objectFacade.deleteObjectAttributeBean(objAttBean.id, DO_NOT_DISPATCH)

 

But if you still want to store multiple attribute at once, you can do that by updating the MutableObjectBean with setObjectAttributeBeans() then call the objectFacade.storeObjectBean(mutableObjectBean) method.

The challenge is that when you use setObjectAttributeBeans(), you have to include all the attributes, not just the ones you wish to update.

There might be better ways to do that, but here is a method I created that takes a map of attributename:value and replaces all the attributes for the object that are in the map without impacting the other existing attributes:

https://bitbucket.org/peter_dave_sheehan/groovy/src/2eceb9b8495852bf1f93a5f6308837e827f4411b/jiraserver/insightUtils/insight/InsightUtils.groovy#lines-491

Dave Ellard June 9, 2022

Perfect. I had exactly the same problem and your solution has fixed it for me.

Alex
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.
December 11, 2023

@PD Sheehan thank you answer! it's perfect 

exactly what is needed , part :

DO_NOT_DISPATCH
0 votes
Marina Veselić April 26, 2022

Thank you! 

In the api version, I was looking at those methods and they were not included. And your utils file is excellent! I will try out the proposed options! You helped a lot!

Cheers,
Marina

Suggest an answer

Log in or Sign up to answer