Have you ever noticed your User Event script gets executed automatically. If yes and you don’t want this to be happened, then this will help you.
You may not have noticed that in netsuite, when a scheduled script runs it also triggers the User Event script. Even I had never noticed before. Some days before I saw some User Event scripts got executed automatically in my current project, then I searched and found the reason that a Scheduled script can trigger a User Event script.
But this shouldn’t be happened always. Then I searched and got a solution which I want to share with you.
In my project, for Sales Order record there are around 10 User Event scripts which include function for After Submit Event.
So when nlapiSubmitRecord(salesorderrecord); executes from Scheduled script, it triggers all the User Event scripts for that Sales Order record automatically.
To avoid this, we can restrict the User Event script to be triggered from Scheduled script.
It can be done in two ways:
1. If we have some User Event scripts that are needed to be triggered from Scheduled script and some are not needed, then we can restrict from those User Event scripts which we don’t need to be triggered by:
if(nlapiGetContext().getExecutionContext() == “scheduled”) { //Do nothing return false; } else { //Do whatever you want to do in this User Event script }
2. If you know, none of the User Event scripts are needed to be triggered from Scheduled script,
then you can restrict from Scheduled script, by which you don’t have to do the restriction from all User Event scripts individually.
For this while submitting the record in Scheduled scripr write:
nlapiSubmitRecord(salesorderrecord, {disabletriggers : true, enablesourcing : true}); instead of writing nlapiSubmitRecord(salesorderrecord).