Many of the tutorials in this series have been about the Client Script. If you have been following along, you should understand how to create and use client scripts in different basic scenarios. Now we can start touching on the basics of User Event scripts. When we are done going through use cases and scripting scenarios of User Event scripts, you should be able to create basic scripts on your own. Before jumping into an example User Event script, let’s take a look at the differences between Client Scripts and User Event scripts and when you should pick one over the other.
Client Script Vs. User Event Script
You can do some of the same things with both Client scripts and User Event scripts. So which one should you choose? Here are some basic differences that can help you decide which one to use for a customization.
- Where the Script Runs
- Clients Scripts run in the browser. That means when you load a record the client script starts to run, and it is immediately available to perform actions when you click around on the record. That is the reason you can make it do something when you change a field.
- User Event Scripts run on the server. Unlike a Client Script, the User Event Script is not immediately available when you load a record because it runs on the server, not the browser.
- Performance and Speed
- Client Scripts will only run as fast as your computer. Since they run in the browser, they are using your computer’s resources to do the work. So if you have a generally slow computer a client script will run slowly.
- User Event Scripts run faster than Client Scripts. Since User Event Scripts run on NetSuite’s server, they have access to more powerful resources. That means unless all your users have a super computer, User Event Scripts will have a lower impact on overall performance than Client Scripts.
- Trigger Points
- Client Scripts have 10+ trigger points. Since Client Scripts are immediately available to perform actions as you change fields and add lines, there are a lot of trigger points to choose from.
- User Event Scripts have 3 trigger points. The only time a User Event Script can be triggered is when a record is loaded and when it is submitted. The Before Load trigger point runs when a record is loaded, and the Before Submit and After Submit triggers are available when the record is submitted.
Deciding Which Script To Use
Based on the differences mentioned above, there is a basic thought process I go through to determine whether to use a Client Script or a User Event Script.
- If an action needs to be performed as fields are changed or lines or added, the only option is to use a Client Script.
- If you need to prevent a user from saving the record if conditions are met, use a Client Script.
- If you do not absolutely need one of the client script triggers to perform an action, use a User Event Script.
- If you need to perform actions (especially if they are more complication actions) when loading or submitting a record, use a User Event Script.
You may run into situations where you absolutely need to use a Client Script, but due to the amount of work the script is doing it results in a terrible lag when entering record information. There is a way to get rid of that lag that I will discuss in a future more advanced tutorial. There are also options to greatly improve the performance of complicated User Event Scripts.