Calling User Event Script from another User Event


As a netsuite solution provider User event scripts are executed on the NetSuite server. They are executed when users perform certain actions on records, such as create, load, update, copy, delete, or submit. Most standard NetSuite records and custom record types support user event scripts.

The Most important thing is User event scripts cannot be executed by other user event scripts or by workflows with a Context of User Event Script. In other words for netsuite customization, you cannot chain user event scripts.
You can execute a user event script from a call within a scheduled script, a portlet script, or a Suitelet. I will help you to show how User event can be called from another User event Script using Suitelet.
As we all know we cannot chain User event. Work around to this is to create a Suitelet that has the same logic as that of first User Event Script. Consider the use case given below:

In NetSuite Implementation Create or edit an Inbound Shipment record and upon saving, the After Submit function of the User Event script deployed to it will also update the Purchase Order associated with the Record and save.
The Purchase Order has another User Event Script deployed to it and is also triggered on After Submit.

The User Event script on Purchase Order updates fields. However the User Event script deployed on
the Purchase Order is not triggered since submitting the Inbound Shipment record is from another
User Event script. N/redirect Module to redirect to Suitelet on the After Submit function of User Event, passing the parameters needed like the Record Type and Record Id.

The sample code below describes information from the Inbound Shipment User Event Script that passes the parameter Record Id to the Suitelet.

The page will redirect to Suitelet on After Submit function and pass the parameters to it
C:\Users\Surya\Desktop\sup1.PNG




Now it’s time to create Suitelet which will update the Purchase Order, The updated record will be able to trigger User event deployed to it. Refer the below screenshot for the Suitelet.
C:\Users\Surya\Desktop\sup2.PNG




In this way we can use schedule script and portlet also for the other use cases where business requirement is rotating around the concept of triggering user event from another user event script.

Comments

  1. Nice Article! I liked your blog because what you said in your article is easy to understand. Thanks for this article that you have shared here NetSuite suitescript

    ReplyDelete

Post a Comment

Popular posts from this blog

USING CASE (IF AND ELSE) IN NETSUITE SAVED SEARCH- NETSUITE ACADEMY

Work Around the 1000 Row Limit Returned by Saved Searches in Netsuite