RE: Stop scheduled script using parameter

Hi all,

i wrote a scheduled script for un drop off orders  , i need to control the script by check box so when it is true the script run and when it is disable the script stop, i create a user script parameter with type check box, but i can’t control the script after i execute it

any help will be appreciated

* @NApiVersion 2.0
* @NScriptType ScheduledScript
define([‘N/search’, ‘N/record’, ‘N/runtime’, ‘N/task’, ‘N/log’], function(search, record, runtime, task, log) {
function execute(context) {
if (context.type == context.InvocationType.ON_DEMAND)
var searchStop = runtime.getCurrentScript().getParameter(‘custscript2’);
log.debug({ title: ‘STOPONOFF’, details: searchStop });

var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
var scriptID = runtime.getCurrentScript().id;
var mySalesOrderSearch = search.load({
id: ‘customsearch1199’

function stop() {

var scheduledScript = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT
scheduledScript.scriptId = scriptID;
scheduledScript.deploymentId = ‘customdeploy9’;
scheduledScript.params = {
searchStop: false

var resultSet =;
var results = resultSet.getRange({ start: 0, end: 1000 });
for (var i = 0; i < results.length; i++) {
var myrec = record.load({
type: record.Type.SALES_ORDER,
id: results[i].id,
isDynamic: true
remainingUsage = runtime.getCurrentScript().getRemainingUsage();
searchStop = runtime.getCurrentScript().getParameter({ name: ‘custscript2’ });
log.debug({ title: ‘remainingUsage’, details: remainingUsage });

if (remainingUsage <= 100 || i == 999) {
log.debug({ title: ‘STOPONOFF’, details: searchStop });
var scrStatus = task.checkStatus(scheduledScript);
if (scrStatus.status == ‘QUEUED’)
// log.debug({ title: ‘sales order id’, details: scrStatus.status });

function undropoff(dyRec) {
log.debug({ title: ‘sales order id’, details: });
fieldId: ‘custbody_sor_dropoffstatus’,
value: ‘NOT_STARTED’
fieldId: ‘custbody_sor_dropoffqr’,
value: ”
fieldId: ‘custbody_sor_dropoffimageurl’,
value: ”
fieldId: ‘custbody_sor_dropoffstarttime’,
value: ”
fieldId: ‘custbody_sor_dropoffarrivetime’,
value: ”
fieldId: ‘custbody_sor_dropoffcompletetime’,
value: ”
fieldId: ‘custbody_sor_dropoffcanceltime’,
value: ”
fieldId: ‘custbody_sor_dropoffcancelreason’,
value: ”
fieldId: ‘custbody_ord_dropoffcashtocollect’,
value: ‘0’
enableSourcing: true,
ignoreMandatoryFields: false
title: ‘Debug’,
details: ‘Done’ +

}return {
execute: execute


butterflyeffect Rookie Asked on February 14, 2021 in SuiteScript.

Can you edit your post and use the code formatting? It makes it so much easier to read

on February 16, 2021.
Add Comment
2 Answers

You can’t use script parameters to control a scheduled script like you’re trying to. When a scheduled script is executed, NetSuite takes a snap shot of the Script parameter values and that’s all the script can access during that invocation.


Is looking up values from this snapshot. When it’s started over it will pick up any changes to params. For what you want to do you’re better off with a custom record handling your runtime control, then the script fetches that single record at whatever frequency appropriate. Mind you, this is a bad practice to be hammering the database like that, but not too bad as custom record access is fast, especially considering you can use search.lookupFields

I was thinking if there was a way to use the session state repo for this, but the scheduled job will run as System and the SuiteLet (What I was thinking could serve as a control panel) will run as a user. Maybe a SuiteLet that ran a scheduled job to set the session value, but Yuck! – that would be pretty ugly.

Rookie Answered on February 16, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.