Scenario
A user would like to ensure that a User Event Script is triggered when a Scheduled Script is run.
Solution
In order for a Scheduled Script to trigger a User Event script of a record that it touches, there are some setup and pointers that should be taken note of:
- The User Event Script should be set to Status: Released.
When running a Scheduled Script, the user that will be logged as the one who triggered the script is -System-. If the User Event script is not set to Released (e.g possibly set to Testing), only its owner can trigger the script. Since we cannot set -System- as the owner of the User Event script, we need to ensure that the script will be triggered regardless of the user, hence, we need to set the status to Released.
- On the Deployment of the User Event Script, Select All must be marked for Roles or at least to Administrator.
When running a Scheduled Script, notice that the Execute as Role on the Deployment is set to Administrator by default and cannot be changed. We need to ensure that the User Event script is set to Apply on All Roles or at least to Administrator so that it will be triggered.
Below steps demonstrate how to trigger a User Event Script deployed on a Customer Record when using a Scheduled Script:
1. Create Scheduled Script
1. Create a .js file for the Scheduled Script using the sample code below to update a specific Customer record:
2. Navigate to Customization > Scripting > Scripts > New
3. Choose File: Upload .js file
4. Click Create Script Record
5. Script Type: Click Scheduled
6. Name: Enter Name
7. Click Scripts
8. Function: Enter updateCustomer_scheduled
9. Click Save
10. Click Deploy Script
11. Title: Enter Title
12. Status: Select Scheduled
13. Schedule: Select a Schedule
14. Click Save
2. Create User Event Script
1. Create a .js file for the User Event Script using the sample code below to update a specific Customer record:
2. Navigate to Customization > Scripting > Scripts > New
3. Choose File: Upload .js file
4. Click Create Script Record
5. Script Type: Click User Event
6. Name: Enter Name
7. Click Scripts
8. Before Submit Function: Enter updateCustomer_UE
9. Click Save
10. Click Deploy Script
11. Applies To: Select Customer
12. Audience: Select All or Administrator
13. Status: Select Released
14. Click Save
Note: Once the Scheduled Script is executed, notice that there are two fields (e.g Comments and Phone) that will be updated on the Customer record based on what is specified on both script types.
Disclaimer
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.