Referencing Script Parameters

You can use the Script.getParameter(options) method to reference script parameters that you create. This method is included in the N/runtime module, and you can use other methods in this module to work with scripts and script objects. For example, use runtime.getCurrentScript() to obtain a runtime.Script object that represents your script. For more information, see N/runtime Module.

Before you can reference script parameters in your script, you must create them using the NetSuite UI. To learn how, see Creating Script Parameters. When you create a script parameter, make sure to remember the ID that you used (or the ID that was generated automatically for you). You must use this ID in your script to obtain the value of the script parameter.

The following example from a Suitelet obtains the value of a script parameter called custscript_mycheckbox:

          // Add a script parameter called Check Box Required
var myField = Form.addField({
    id: 'custscript_mycheckbox',
    label: 'Check Box Required',
    type: serverWidget.FieldType.CHECKBOX
});

// Obtain an object that represents the current script
var myScript = runtime.getCurrentScript();

// Obtain the value of the Check Box Required script parameter
var scriptParameterValue = myScript.getParameter({
    name: 'custscript_mycheckbox'
}); 

        

You cannot write to a script parameter using SuiteScript. Although you can read from these fields, you cannot write to them. The only time you can pass a value to a script parameter outside of the UI is when you call task.create(options) to schedule a script.

For a complete example working with script parameters in a SuiteCloud project, see Disable Tax Fields.

General Notices