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?
All Replies (4)
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.
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.