Prevent User Event Scripts Running On CSV Imports

Written by
Manuelito Macalinao
Published on
February 29, 2024 at 7:27:56 AM PST February 29, 2024 at 7:27:56 AM PSTth, February 29, 2024 at 7:27:56 AM PST
Scenario

With the "Run Server SuiteScript and Trigger Workflows" option enabled (inSetup > Import/Export > CSV Import Preferences) User Event scripts deployed on a record will also run for CSV Imports for the very same record.

However, one may wish to prevent such behavior.

Solution
To prevent a script or a part of a script from running on CSV Import, one needs to enclose one's code by the following if statement.
SS 1.0
var currentContext = nlapiGetContext(); if(currentContext.getExecutionContext() !='csvimport') { // Do not forget to close the if statement at the end of the code }
SS 2.0
if(runtime.executionContext != runtime.ContextType.CSV_IMPORT) { // Do not forget to close the if statement at the end of the code }
In case you need to prevent all of the code from running do as follows.
SS 1.0
functionmyBeforeSubmitFunction(type, form){var currentContext =nlapiGetContext();if(currentContext.getExecutionContext()!='csvimport'){// Insert your code here to prevent it from running on CSV Import}}
SS 2.0
functionmyBeforeSubmitFunction(context){if(runtime.executionContext != runtime.ContextType.CSV_IMPORT){// Insert your code here to prevent it from running on CSV Import}}

If you would like to prevent only part of your script from running for a CSV Import, please do the following.

SS 1.0

functionmyBeforeSubmitFunction(type, form){// Code is ALWAYS being executedvar currentContext =nlapiGetContext();if(currentContext.getExecutionContext()!='csvimport'){// Code is NOT being executed on CSV Import}else{// Code is being executed ONLY on CSV Import}// Code is ALWAYS being executed}

SS 2.0

functionmyBeforeSubmitFunction(context){// Code is ALWAYS being executedif(runtime.executionContext != runtime.ContextType.CSV_IMPORT){// Code is NOT being executed on CSV Import}else{// Code is being executed ONLY on CSV Import}// Code is ALWAYS being executed}