Scheduled Script

Hi There,


When you want to schedule a functionality , or task or we can call it a job , we use Scheduled Script.
Netsuite uses SuiteCloud Processors to schedule and perform task. Scheduled Script is server side scripting
and uses server side Suite Scripts. These script deployed to perform a task in future and/or recurring future job.
Example: sending collection email to customer based on days 15 days, 30 days, 45 days and 60 days.

Schedule Script can:
1. trigger another schedule script ,
2. send data to suitelet,
3. send data to restlet
4. when saved trigger user events on record.
and much more

Governance Limit:
Scheduled Script has 10,000 usage limit, developer can stop and retrigger script from the point it stopped
or use logic to process next set of data.

Scheduled Script Submission
User can submit and process script in one of 3 ways:
1. Run it as 1 time event or recurring event
2. On Demand execution using Save and execute ( script should be in testing status)
3. Triggered and executed from other script  using task.ScheduledScriptTask . In this case
status should be not scheduled to run script from another server side script.

Scheduled Script Status Page

This page shows the current and past runtime statuses of all scheduled script instances in your
 account that have submitted in the last 30 days.
Status and Description:
Pending: The script is submitted and is waiting to be processed.
Deferred : script is eligible for processing but waiting for already running job to get finish.
Processing: The script is running.
Retry: The script entered the processing state and failed to complete normally. It is eligible to be retried.
Complete: The script completed normally.
Cancelled: The script was canceled during or before script execution.
Failed: The script began processing but failed to complete. 


Script Entry Point:
Schedule script use execute function as execution entry point. 

User can use context.InvocationType Enumeration for following values:
SCHEDULED
ON_DEMAND
USER_INTERFACE
ABORTED
SKIPPED

Developer can use above enum in code to trigger script on different type of InvocationType. 
Example:
if (context.type !== context.InvocationType.ON_DEMAND) return


 Schedule Script Example:
 /**
 *@NApiVersion 2.x
 *@NScriptType ScheduledScript
 */
define(['N/search', 'N/record', 'N/email', 'N/runtime'],
    function(search, record, email, runtime) {
        function executeScript(context) {
        if (context.type !== context.InvocationType.USER_INTERFACE)
                return;
        // add you logic here
// use search module to search,
// record module to load/create/copy etc for record
// use email module to email, use runtime to get
//value from script parameter
var ngId= runtime.getCurrentScript()
.getParameter("custscript_netsuiteguru_id");


        }
        return {
            execute: executeScript
        };
    }); 


 Step fpr Schedule Script :

Step 1: create file in javascript (as above) 
Step 2: Go to Customization>Scripting>Scripts>New> Upload File.

Step 3. Click on Create Script Record button.
Step 4: Enter Name, ID, populate other fields as per need.
Step 5:Click on Save and Deploy
Step 6: Update Title if needed, enter id .
Step 7: Select Status , log level, priority,
Step 8: Schedule Script using Schedule TAB's options, example, select SINGLE EVENT if you want script
to run once only, or select daily and populate related field.If there is any end data populate end date field else check No End Date checkbox.

Step 9: Save.

**** if you want to test script, status should be testing and click on save , then edit deployment again and click on save and execute. You have to save only first time when you change status to testing , every other time you will see save and execute option while mouse hover on Save button.
**** If you want to run this script as on demand, select status as Not Scheduled and save. You can trigger this deployment using user event/scheduled script/ suitelet or any other server side script.

some related Links
Deal with limits
Netsuite Limits
More than 1000 record in search

Please let us know if you have any question in Scheduled Script. Share if you like this post.
 Thanks 
Netsuite Guru


Download Netsuite Guru Android App
  Join us on Linkedin
Our FB Page

Comments

  1. Great blog,
    can you please give me code how I can trigger it via user event and pass the argument,. I have purchase order and after it is loaded the lines get update with cost template, unfortunately due to limit of 1000 unit it failed with SS_LIMIT exceeded, so I decided to developed code where if there is limit reach I can forward request to schedules script to complete rest of the job. Like if there are 100 lines of PO then it will use user event but if more than that then PO with remaining lines be update by schedules script.

    ReplyDelete
    Replies
    1. Sorry for very late reply, Issue might not be there definitely but adding URL for reference.
      We have logic structure for Suitescript 1.0 but you can change it into 2.0
      https://netsuiteguru.blogspot.com/2016/12/how-to-get-more-than-1000-records-in.html

      Delete
  2. Hi thanks for providing the solution . lets say if i have a user event script that is failed due to some maintenance then how can i use scheduler in that case for get the result of the failed transactions

    ReplyDelete

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin