User Event Scripts are one of the most common script types to work with. In the next several blogs I will walk through some example User Event scripts, and this first blog will introduce the basic setup of the User Event Script Before Load trigger.
Before Load Trigger
The beforeLoad function in User Event Scripts triggers when a record loads in your NetSuite instance. You can do actions as a record loads when it is . . .
- Created
- Copied
- Edited
- Viewed
Here are some examples of what you can do with the beforeLoad function in a User Event Script:
- When creating or copying a record, automatically populate fields based on the current user’s role.
- When viewing record, hide critical information that the current user does not need to see.
- If you edit a record, automatically update fields when a certain criterion is met.
User Event Basic Structure
The basic structure of User Event Scripts is similar to Client Scripts. You have to include any module that the script will need.
define(['N/record', 'N/search'], function (record, search) {
//everything else will go inside here
});
In this example, the script includes the N/record
and N/search
modules. They are added to the script here — define(['N/record', 'N/search'],
and are given a name to be used in the script — function
(record, search)
.
You also need to add the section that displays information about what the script type is and what the suitescript version is. When you add that in, here is what the script should look like:
define(['N/record', 'N/search'], function (record, search) {
/**
*@NApiVersion 2.0
*@NScriptType UserEventScript
*/
//everything else will go inside here
});
Before Load Basic Structure
You can add the beforeLoad
trigger to the script by adding the beforeLoad
function and then adding it to the return section of the script. Here is what the basic beforeLoad
function looks like:
function beforeLoad(context) {
//all your Before Load actions will go in here.
}
And the return section will look like this:
return {
beforeLoad: beforeLoad
}
When you add that to the rest of the script, it will look like this:
define(['N/record', 'N/search'], function (record, search) {
/**
*@NApiVersion 2.0
*@NScriptType UserEventScript
*/
function beforeLoad(context) {
//all your Before Load actions will go in here.
}
return {
beforeLoad: beforeLoad
}
});
Conclusion
We hope learning about the User Event Script Before Load trigger has been helpful! In the next tutorial, we will take this basic structure and add to it to create an example Before Submit customization.
If you would like to learn more, check out other blogs in our NetSuite Development series or visit the NetSuite help documentation on this topic. And don’t forget to subscribe below to never miss another post!