Hi all, does anyone know if it is possible to make...
# suitescript
a
Hi all, does anyone know if it is possible to make a user event script trigger only when a journal entry has been created by a certain script? The use case is that we have journal entries being created by a scheduled script (as part of an integration) that would bypass approvals. (Workflows won't work. I want to use the condition that it is being created by a certain script deployment to bypass approval process)
e
You might be able to determine this from information available in the
context
passed to the User Event as well as from the
N/runtime
module, but I'm not sure about that. One approach is to have your creating script set a field on the JE, perhaps a checkbox that indicates it came from the Scheduled Script or more generally that the JE can bypass approvals. If the box is checked, your UE can safely ignore the JE. Another approach might be to search the System Notes for which User created the JE.
c
I'd go w/ the checkbox and not have to search system notes myself
n
If there's only one scheduled script that triggers the UE you could check runtime.executionContext for SCHEDULED.
e
^ I was hesitant to recommend this. It definitely works, but then you have to guarantee there will only ever be one Scheduled Script ... or hope that you remember to update the code when a new one comes along 🙂
Though if you're going to use the
runtime
module already, I suppose you could also look at the specific script ID. I actually wasn't sure what the
executionContext
would be in the case of a Scheduled Script triggering a UE.
n
Not sure if you can check the session object, might tell you the script id / deployment, but that might be the UE details, so hmmm.
s
NetSuite doesn’t offer any indication of which script is triggering the event, only the execution context, as mentioned above. Do you have access to modify the scheduled script? If so, you can also use the n/cache module to set a cache value and look for that via the UE script. Is the script being scheduled to run as a specific role? If so, you could potentially create a role with the same permissions that is used in the scheduled script deployment, then run as that one-off role, and check for that role and the script context in the UE..
🤔 1
c
Man i wish it did tell you the triggering script soley for debugging client accounts/logs where some random script is triggering a script and you gotta get support involved to see what it is
🤯 1
💯 2