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.

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

Object type after moving in insight automation is the same as before the move

Marina Veselić November 9, 2021

Hello everyone,

I have an object in Insight. It is an object type that has two parents. The object type is called Desktop. There is an object type called Laptop that is in the same level and has the same parents as the object type Desktop.

So, I've set up Insight automation that is trigered on move event, there are no conditions, and the acton is groovy script. It has lines as follows:

def objectTypeCurr=objectTypeFacade.loadObjectTypeBean(object.getObjectTypeId());
log.info("objectTypeCurr?"+objectTypeCurr)

When I move the object from Desktop to Laptop the log says:

2021-11-09 14:37:28,496 [insight-event-3] | Execute Rule action (AutomationRuleGroovyScriptAction): Done, id:80, event [id: 78, iql: No iql, condition: None
2021-11-09 14:37:28,496 [insight-event-3] | Execute Rule action (AutomationRuleGroovyScriptAction), Result: Groovy script (Update Tier categories.groovy) executed.
2021-11-09 14:37:28,168 [insight-event-3] | objectTypeCurr?ObjectTypeBean [id=1210, name=Desktop]
2021-11-09 14:37:28,168 [insight-event-3] | Execute groovy script: \scriptrunner\scripts\insight\Update Tier categories.groovy
2021-11-09 14:37:27,980 [insight-event-3] | GroovyScriptAction, got absFilePath: \scriptrunner\scripts\insight\Update Tier categories.groovy
2021-11-09 14:37:27,980 [insight-event-3] | Execute Rule action (AutomationRuleGroovyScriptAction): Start, id: 80, event [id: 78, iql: No iql], condition: None
2021-11-09 14:37:27,980 [insight-event-3] | Object name: 2, id: 1508224
2021-11-09 14:37:27,980 [insight-event-3] | doAction(), called for event class: InsightObjectMovedEvent
2021-11-09 14:37:27,980 [insight-event-3] | Role Actor configured, and will be run as user with key: robot
2021-11-09 14:37:27,980 [insight-event-3] | Got rule and event for insightObjectAsyncEvent: null, id: 78 - InsightObjectEvent eventType: OBJECT_MOVED, rule id: 40, name: Tier category update with script, isActive true, objectRuleEvent id: 78 and object: 2 (TIAPBIS-1508224)

Sooo... After the move, the object type is still Desktop. Is this a bug? If it is a feature, how do I access the current object type after the move has been completed?

I need the correct object type because I set some other things in motion.

Cheers, 
Marina

 

1 answer

1 accepted

0 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.
November 9, 2021

I haven't tried this specific scenario.

But I have another case where I perform a MOVE using groovy code.

And that move operation I found out took place in an asynchronous method. In other words, I start the move and the next line of code executes immediately. But in the background, the move is still happening.

So I had to institute a "moveAndWait" method so that I can wait for the move operation to complete before performing my downstream operations.

It would seem, based on your observation, that the ObjectMoved event is triggered at the beginning of the move operation, not at the end of it.

I don't know if it's possible to connect to a progress object from the event or if there is another event that can detect when the move operation is complete.

So maybe you can try to just add some arbitrary delay before looking up the object type or performing your other operations.

Marina Veselić November 10, 2021

Hi Peter!

So, it's a feature. :) Thank you very much for an elaborate response. 

I don't like arbitrary delays. And I think it may have the object cached. That being said, I will try to put a delay and I will try to load the object after it, and not use the "object" variable. Also, I need to reproduce a slow working environment because everything works fine when everything is fine. :) I will let you know the results. 

Cheers,
Marina

Marina Veselić November 10, 2021

FYI, this code actually worked!

int objectIdTemp=object.id;
def objectTypeCurr=objectTypeFacade.loadObjectTypeBean(object.getObjectTypeId());
log.info("objectTypeBeforeDelay?"+objectTypeCurr)

int delay=21474397;
log.info('delay start: '+delay);
while(delay>0)delay--;
log.info('delay end: '+delay);

def objectAfterDelay=objectFacade.loadObjectBean(objectIdTemp);

def objectTypeAfterDelay=objectTypeFacade.loadObjectTypeBean(objectAfterDelay.getObjectTypeId());
log.info("objectTypeAfterDelay?"+objectTypeAfterDelay)

It showed different object types before and after delay... I must admit, I didn't try to study events and how to get the info I need (and you suggested). If anyone has any experience with it, this is the time to share. :)

Hope this helps someone. 

Cheers,
Marina

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.
November 10, 2021

Maybe you can try to do something like this:

def targetObjType = 'Laptop';
def getObjType = {objectTypeFacate.loadObjectTypeBean(object.objectTypeId) }
def timeout = 60000 //milliseconds
def timer = 0
def waitInterval = 250
while (getObjType.name != targetObjType && timer<timeout){
sleep(waitInterval)
timer += waitInterval
}
assert timer < timeout, "Cancelling automation after timeout waiting for $targetObjType"

//do your post move operations

Suggest an answer

Log in or Sign up to answer