How can I exclude a User Event from getting trigge...
# suitescript
a
How can I exclude a User Event from getting triggered by a mass update?
d
If (context.type == ‘xedit’) I believe
a
Thanks @D17339
d
Check the context type options enum n u can update
a
@D17339 @Azi context.type === 'xedit' is going to exclude any inline editing operation, you should be doing two things: 1- Use NetSuite enumerations
context.UserEventType.XEDIT
2- Don't use XEDIT in this case you should be using:
runtime.executionContext === runtime.ContextType.CSVIMPORT
💯 2
a
@alien4u You mean #1 in general and #2 in this specific case?
n
Also, you might want to change that on the deployment level of the script and in the execution context Multiselect exclude the Mass Update. This way it won't even get to start the script thereby increasing the performance somewhat.
💯 1
a
@Azi #1 general advise... #2 is your specific use case.
a
Got it. Thanks
Very strange. I did both @alien4u and @Nik suggestions and neither one worked.
a
You change this to MASSUPDATE right?
CSVIMPORT
The right enumeration is
runtime.ContextType.CUSTOMMASSUPDATE
a
Yes. But its weird. None of my logs work either, but it is giving me a system error by line of code I am trying to circumvent
a
Show code...
a
Copy code
function beforeSubmit(sc) {
      
       log.debug('runtime.executionContext', runtime.executionContext)
       log.debug('runtime.ContextType.CUSTOMMASSUPDATE', runtime.ContextType.CUSTOMMASSUPDATE)
      
       if(runtime.executionContext === runtime.ContextType.CUSTOMMASSUPDATE){
         log.debug('runtime.ContextType.CSVIMPORT', runtime.ContextType.CUSTOMMASSUPDATE)
         return
       }
      
    	var cust = sc.newRecord.getValue('entity')
        log.debug('csl_ak_ue_so_validate_rx.js CUST', cust)
    	var address = sc.newRecord.getValue('shipaddresslist')
    	var licenses = search.create({
    		type: 'customrecord_some_custom_record',
    		filters: [['custrecord_csl_approval_status', 'anyof', 2], 'and',
    			['custrecord_csl_cust', 'anyof', cust], 'and',
    			['custrecord_csl_exp', 'after', format.format({type: format.Type.DATE, value: new Date()})]],
    		columns: ['custrecord_csl_class', 'custrecord_csl_dea_address', 'custrecord_csl_lic', 'custrecord_csl_exp']
    	}).run() ...
The problem is getting newRecord.getValue('entity') on a mass update So I am trying to prevent this whole code from running on mass update In the UI as @Nik suggested As well as in this code, as you suggested. But not of my logs are even getting logged. Do mass updates show logs if they trigger a User Event?
a
You are missing a dot here.
Copy code
runtime.ContextType.CUSTOMMASSUPDATE
Or not...
your are not...
I assume you are importing the 'N/runtime' module correct?
a
Yes
a
This condition should be doing the trick... what do you see in the logs?
Copy code
if(runtime.executionContext === runtime.ContextType.CUSTOMMASSUPDATE){
    log.debug('runtime.ContextType.CSVIMPORT', runtime.ContextType.CUSTOMMASSUPDATE)
    return
}
a
But not of my logs are even getting logged. Do mass updates show logs if they trigger a User Event?
a
No if you remove it from the execution context in the deployment from the UI, you should not mix solutions, especially if the solutions overlaps... try one thing first... then try another.
👍 1
a
Okay so
runtime.executionContext
= "USEREVENT" and
runtime.ContextType.CUSTOMMASSUPDATE
doesn't have value
So the problem is that the execution context is a user event not a mass update. Is there any way get what the execution context that triggered the user event in the first place is?
d
In SS 1.0 I have it working with:
Copy code
if (nlapiGetContext().getExecutionContext() === 'custommassupdate')
Not sure about SS 2.0, and alien4u is right, you should be using enums
n
@Azi If you followed my solution, the UE should not trigger at all if the context is mass update, and hence there will be no log. But in case of it is executed by UserEvent it will log it as it should. Also, I think its runtime.ContextType.CUSTOM_MASSUPDATE but not sure. If "runtime.ContextType.CUSTOMMASSUPDATE" doesn't work, "runtime.ContextType.CUSTOM_MASSUPDATE" should
a
@Nik You are correct that the correct syntax is
runtime.ContextType.CUSTOM_MASSUPDATE
But its very strange. The runtime.executionContext is logging as
USEREVENT
@Nik And When I try your solution it also still runs. For some reason it is not registering that this is being caused by a mass update. Any suggestions?
n
Strange. That shouldn't happen. I have User Events that that identify when a Mass Update Runs. Probably your Mass Update is triggering a UE that in turn triggers the script you are trying to by pass. In which case, better would be to exclude the Map Reduce Context in the script which triggered your script.
a
Hmmm. Interesting. Thats a good point. I'll look into that. I will also post again in main channel for any new ideas
@Nik Maybe its because I a manually running the Mass Update instead of scheduling it?