Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The NetSuite Pro

The NetSuite Pro Logo The NetSuite Pro Logo

The NetSuite Pro Navigation

  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • Advanced PDF Templates in NetSuite
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • Advanced PDF Templates in NetSuite
  • Blog
  • Contact Us
Home/ NetSuite Scripting/Working with Script Parameters in SuiteScript 2.1

Working with Script Parameters in SuiteScript 2.1

🔹 What are Script Parameters?

Script parameters let you make your SuiteScripts configurable without hardcoding values.

Examples:

  • API credentials (username, token, secret)
  • Default subsidiary or location IDs
  • Threshold values (e.g., “minimum order amount”)
  • Boolean switches (on/off feature flags)

Instead of rewriting your script, you add a parameter → deploy the script → set the parameter value in the deployment record.


🔹 Types of Parameters

When you define a parameter in your script record, you choose a type. Common ones:

  • Text → strings like “sandbox” or “production”
  • Integer → numbers like “10”
  • Checkbox → true/false values
  • Select → picklist linked to a NetSuite record (Customer, Account, Subsidiary, etc.)
  • Date/DateTime → scheduling values

🔹 Accessing Script Parameters

SuiteScript gives you APIs in the N/runtime module to get parameters:

  • runtime.getCurrentScript().getParameter({ name: 'custscript_myparam' })
  • Always use the internal ID of the parameter (starts with custscript_).

🔹 Example 1 — Simple Text Parameter

Scenario: Add a parameter called custscript_api_url for your REST API endpoint.

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/runtime'], (runtime) => {
    const execute = () => {
        try {
            // 1) Get the current script context
            const script = runtime.getCurrentScript();

            // 2) Fetch parameter value by its internal ID
            const apiUrl = script.getParameter({ name: 'custscript_api_url' });

            // 3) Use parameter in logic (here we just log it)
            log.debug('Configured API URL', apiUrl);

            // In a real integration, you would make HTTP calls to this apiUrl
        } catch (e) {
            log.error('Error using script parameter', e.message);
        }
    };
    return { execute };
});

đź’ˇ Explanation:

  • In deployment, set the custscript_api_url to something like https://api.test.com.
  • The script can run against different environments without code changes.

🔹 Example 2 — Integer Parameter for Batch Size

Scenario: Control how many records to process per run.

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/runtime'], (runtime) => {
    const execute = () => {
        try {
            const script = runtime.getCurrentScript();

            // Get integer parameter
            const batchSize = parseInt(script.getParameter({ name: 'custscript_batch_size' })) || 50;

            log.debug('Batch Size', batchSize);

            // Example: fetch that many results in search
            // search.run().getRange({ start: 0, end: batchSize });
        } catch (e) {
            log.error('Error using batch size parameter', e.message);
        }
    };
    return { execute };
});

đź’ˇ Explanation:

  • Instead of hardcoding 50, admin can set batch size in the deployment.

🔹 Example 3 — Checkbox Parameter

Scenario: Toggle between Sandbox Mode and Production Mode.

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/runtime'], (runtime) => {
    const execute = () => {
        try {
            const script = runtime.getCurrentScript();

            // Checkbox parameters return "T" (true) or "F" (false)
            const sandboxMode = script.getParameter({ name: 'custscript_sandbox_mode' }) === 'T';

            if (sandboxMode) {
                log.debug('Mode', 'Running in SANDBOX mode');
                // Do test logic here
            } else {
                log.debug('Mode', 'Running in PRODUCTION mode');
                // Do production logic here
            }
        } catch (e) {
            log.error('Error using sandbox mode parameter', e.message);
        }
    };
    return { execute };
});

đź’ˇ Explanation:

  • Helps switch environments without editing the code.

🔹 Example 4 — Select Parameter (Record Reference)

Scenario: A script should always post to a specific Account (from Chart of Accounts).

/**
 *@NApiVersion 2.1
 *@NScriptType UserEventScript
 */
define(['N/runtime'], (runtime) => {
    const beforeSubmit = (context) => {
        try {
            const script = runtime.getCurrentScript();

            // Select parameter stores the internal ID of the chosen record
            const defaultAccount = script.getParameter({ name: 'custscript_default_account' });

            if (defaultAccount) {
                const rec = context.newRecord;
                rec.setValue({
                    fieldId: 'account',
                    value: defaultAccount
                });
                log.debug('Account Set', `Default account ${defaultAccount} applied`);
            }
        } catch (e) {
            log.error('Error applying default account', e.message);
        }
    };
    return { beforeSubmit };
});

đź’ˇ Explanation:

  • The parameter type is Select → Account.
  • Admin picks an Account in deployment.
  • Script automatically applies it.

🔹 Best Practices

  • Prefix internal IDs with custscript_ for consistency.
  • Always validate parameter values (check for null/empty).
  • Use parseInt/parseFloat for numeric params.
  • Use === 'T' for checkboxes.
  • Store credentials (API keys, secrets) in Script Parameters or NetSuite’s Credential fields, never in code.
  • If parameter values differ per subsidiary or deployment, create multiple deployments with different values.

âś… Key Takeaway

Script Parameters make your SuiteScripts flexible and reusable. Instead of hardcoding, you configure values at deployment time — making it easier for admins to manage and developers to maintain.

Share
  • Facebook

Sidebar

Ask A Question

Stats

  • Questions 6
  • Answers 6
  • Best Answers 0
  • Users 2
  • Popular
  • Answers
  • Rocky

    Issue in running a client script in NetSuite SuiteScript 2.0 ...

    • 1 Answer
  • admin

    How can I send an email with an attachment in ...

    • 1 Answer
  • admin

    How do I avoid SSS_USAGE_LIMIT_EXCEEDED in a Map/Reduce script?

    • 1 Answer
  • admin
    admin added an answer The issue is usually caused by following Wrong script file… September 14, 2025 at 10:33 pm
  • admin
    admin added an answer Steps to send an Invoice PDF by email: define(['N/email', 'N/render',… August 28, 2025 at 3:05 am
  • admin
    admin added an answer This error means your script hit NetSuite’s governance usage limit… August 28, 2025 at 3:02 am

Top Members

Rocky

Rocky

  • 1 Question
  • 21 Points
Begginer
admin

admin

  • 5 Questions
  • 2 Points

Trending Tags

clientscript netsuite scripting suitescript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

© 2025 The NetSuite Pro. All Rights Reserved