How do I avoid trigger "Service: Saving a request" to fire several times?

lock
push_pin
done
Answered
4

I have a trigger on 'Service: Saving a request' which post data to a webservice.

But we see that sometimes data is send send several times right after each other.

I expect the trigger is fired (like if it was a webhook) by different areas of the SuperOffice code updating the ticket/request.

Since I do know where or why I have tried to prevent it by indicating that my code is allready running and should not run again (until finished).

A) Setting eventdata state using ed.setStateValue ("running","yes")
B) Setting global variable using setGlobalVariable("running","yes")

Ex like this:

String working = getGlobalVariable("running");
if (working == "yes")
{
  return;
}

setGlobalVariable("running","yes");

<post to webservice here>

 

But I have no success, maybe the code actually is able to finish before the next time it is fired. but... I never clear the variable.

How do I prevent it from running again sending the same data?

 

 

28 Apr 2023 | 06:18 PM

All Replies (4)

Hi Morten,

 

You could store the status in an ExtraTable ?

28 Apr 2023 | 06:29 PM
yes but, to me it seems a little overkill - at least if someone know if it is possible to prevent the trigger to fire more than once (on the save event) - or if someone know how to communitate between scripts (or instances of the same script).
28 Apr 2023 | 06:34 PM

You could store if your script is currently executing in a custom table (like Bas said) or as a row in the userpreference table, another option maybe could be to use setSessionVariable / getSessionVariable. That is connected to the current user executing the script though, so not sure if that works in a event script context.

Another issue here is what if the data is actually changed twice immediately? and you won't be processing the second change since the script is still processing the first update.

1 May 2023 | 11:27 AM

It turned out that 'Service: Saving a request' was fired even when users where just looking at a ticket.
Ie I ended up using extratable to check if current data had allready been send.

 

17 May 2023 | 01:20 PM

Add reply