Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19: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.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get Insight event type in groovy automation script

Marina Veselić April 22, 2022

Hi,

We have a lot of automation rules in Insight that use groovy scripts. They are pretty similar in regards of condititions and objects that are affected by them. So, we would like to optimize them and merge them into as few automation rules as possible. However...

There are some scripts that have some specific code related to a specific event type. For instance: Object type after moving in insight automation...  Is there a way to get InsighObjectEventType in the automation groovy script?

I know there is some data available through the Rule engine (object, objectUdateList,...), but not the event or event type. 

Cheers,
Marina

1 answer

0 votes
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 23, 2022

I don't think there is anything available in a groovy script that will give you this information.

I looked.

Here is a script where I tried every trick I could find to look for clues:

log.info "This.class: ${this.getClass()}"
log.info "Properties in this:\n${this.properties.collect{"$it.key = $it.value (${it.value.getClass()})"}.join('\n')}"
log.info "MetaProperties in this:\n\t${this.metaClass.properties.collect{"$it.name = $it (${it.type})"}.join('\n\t')}"
log.info "Variables in binding:\n\t${this.binding.variables.collect{"$it.key = $it.value (${it.value.getClass()})"}.join('\n\t')}"
Thread.currentThread().getStackTrace().drop(0).take(50).eachWithIndex{it,i->
log.info "Calling class[$i]: $it.className#$it.methodName($it.lineNumber)"
}

Looking in the insight_automation.log I didn't find anything that was usable.

The best you can do is combine issue create and issue updated and then figure out the type of event it is by examining if objectUpdateList is empty (object created) or not (object updated)

Marina Veselić April 25, 2022

Thank you for your answer! This code will be useful in other situations!

I suppose you mean insight object created/updated instead of an issue, but I get it. The thing that gives me hope is looking at the object's history and objectUpdateList. I see that, when an object is created, its history list is of size 1 and the history bean type is 0.

But to get if there was a move or a change is not that straightforward. Can I suppose that if the first (newest) record in the history bean is of type move (24?) that the object has been moved? And that there is no other way that the move event is written in the history list? I am wondering this because of other automations triggering at the same time and writing in the history list and the fact that when you move an object you can remove links and discard some values.

I don't know if I was clear... :)

 

Cheers,
Marina

P. S. Is there a list of enum values that correspond to the history change type of an Insight object bean?

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 25, 2022

Yes, I meant "object created/updated".

I have not tried to use the object history as a way to determine the most recent event. That might be a good choice.

My feeling is that automation will always be a little bit behind the history creation. I've had times where automation was queued for several hours (after a large bulk change). But the history is always available immediately. 

I don't have any information on the history change types and if there is an enum. I'm not finding that in the javadoc for the public api. It might be in a private class.

Marina Veselić April 26, 2022

Yes, now that you mention it, the delay can be a problem if someone changes an object after the bulk update and before the automation triggers. What would be the history list? And would there be two automations? With the same history list or a different one? Do you have any expirience on that?

Cheers,
Marina

Suggest an answer

Log in or Sign up to answer