Search code examples
parametersnetsuiteschedulesuitescript2.0

How can I pass parameter from Suitelet to Scheduled Script?


I am trying to pass a custom parameter from my Suitelet to my Schedule Script in NetSuite SS2.0, but unsure where I am going wrong. I just get null being passed through. I have a log which provides the correct data while parsing in the Suitelet (from the client), somewhere between passing it from Suitelet to the Scheduled script I am getting lost.

I have tried

var WOObjId = runtime.getCurrentScript().getParameter({name: 'custparam_wo_record'});
var WOObjId = context.request.parameters.custparam_wo_record;

Scheduled Script

define(['N/record', 'N/redirect', 'N/ui/serverWidget', 'N/task', 'N/error', 'N/file', 'N/render', 'N/runtime', 'N/search', 'N/config'],

(record, redirect, serverWidget, task, error, file, render, runtime, search, config) => {

    /**
     * Defines the Scheduled script trigger point.
     * @param {Object} scriptContext
     * @param {string} scriptContext.type - Script execution context. Use values from the scriptContext.InvocationType enum.
     * @since 2015.2
     */
    const execute = (context) => {
                    try{
                        //Get XML File information
                            log.debug('Request Received');
                            var WOObjId = runtime.getCurrentScript().getParameter({name: 'custparam_wo_record'});
                            log.debug('object received', WOObjId)
                        //var WOObjId = [9073,9059]
                            var WOObjLength = WOObjId.length;
                            log.debug('WOObjId', WOObjId + ' length is '+ WOObjLength );

My Suitelet -

(task) => {
    /**
     * Defines the Suitelet script trigger point.
     * @param {Object} scriptContext
     * @param {ServerRequest} scriptContext.request - Incoming request
     * @param {ServerResponse} scriptContext.response - Suitelet response
     * @since 2015.2
     */
    const onRequest = (context) => {
        var WOObjId = context.request.parameters.custparam_wo_record;
        log.debug('Inside Suitelet Call received', 'WO Params: ' + WOObjId);
        executeScheduled(WOObjId);
    }

    function executeScheduled(param) {
        var scriptTask = task.create({
            taskType: task.TaskType.SCHEDULED_SCRIPT,
            scriptId: "customscript_ns_ss_printwo_batchschprint",
            deploymentId: "customdeploy_ns_ss_printwo_batchschprint",
            params: {
                'custparam_wo_record' : param
            }
        });

        var scriptTaskId = scriptTask.submit();

        log.debug("scriptTaskId", scriptTaskId);
    }

    return {onRequest}

});

Solution

  • You have to define the parameter on the scheduled script's Script record. The id you set there is what you'll use for passing the parameter.

    The parameter script ids are not free-form and will end up as custscript* e.g. custscript_wo_record. That is the value you'll have to pass instead of the one prefixed by custparam.