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.

  1. 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.
  1. 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.
  1. 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.
Bonus Information

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.

    Using an Enums Custom Library, Part 1

    In a previous developer post, we introduced a new paradigm for structuring SuiteScript files in a project.As we address some of the details of this structure, we come to the topic of enums. Enums, short for "enumerated types" or "enumerations," is basically a separate...

    Scripting Pattern – Client Script Calling a Suitelet

    In NetSuite development, there are a few common scripting patterns to master. One of these patterns is a kind of automation that connects both the client side and a server side. Today we will be looking at a Client Script calling a Suitelet. In the previous NetSuite...

    SuiteScript Code Structure

    Having a standard method for your SuiteScript code structure can be extremely helpful. Having a set structure provides consistency, preemptively removes difficult roadblocks, and reduces the number and severity of bugs. A Structural Overview This is a cutting-edge...

    SuiteScript Naming Conventions

    SuiteScript naming conventions can prevent NetSuite from becoming messy and help you locate your scripts in NetSuite efficiently. A Quick Blog Roadmap If you have been following along with our SuiteScript blog, we've covered a lot of ground! We have learned about the...

    Handle POST Request in a Suitelet (Build a Suitelet, Part 5)

    Once we design our Suitelet to display helpful information, how do we handle interactions with the Suitelet by a user? In this blog post we will learn how to handle new information posted to the server to perform important tasks. If you're new to this mini-series...
    0
    Would love your thoughts, please comment.x
    ()
    x