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/Scheduled Scripts in NetSuite (SuiteScript 2.1 Guide)

Scheduled Scripts in NetSuite (SuiteScript 2.1 Guide)

🔹 Introduction

Scheduled Scripts run automatically in the background at set intervals or when triggered manually. Unlike Client or User Event scripts, they don’t depend on a user opening or editing a record.

They are perfect for:

  • Running batch jobs (e.g., nightly updates)
  • Cleaning up data
  • Sending reminders or notifications
  • Processing records that don’t need to be handled in real-time

🔹 How They Work

  • Written in SuiteScript 2.1
  • Deployed under Customization → Scripting → Script Deployments
  • Can be scheduled daily, weekly, monthly, or triggered on-demand
  • Can process thousands of records (but heavy jobs may require Map/Reduce)

🔹 Example 1: Simple Log Message

What this script does:

  • Runs in the background and logs a message (useful as a template to test your first deployment).
/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define([], () => {
    const execute = () => {
        try {
            log.debug('Scheduled Script', 'Hello! This is my first scheduled script.');
        } catch (e) {
            log.error('Error in scheduled script', e.message);
        }
    };
    return { execute };
});

🔹 Example 2: Update a Field on Multiple Records

What this script does:

  • Finds inactive customers and reactivates them.
/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/search', 'N/record'], (search, record) => {
    const execute = () => {
        try {
            const customerSearch = search.create({
                type: search.Type.CUSTOMER,
                filters: [['isinactive', 'is', 'T']],
                columns: ['entityid']
            });

            const results = customerSearch.run().getRange({ start: 0, end: 10 });
            
            results.forEach(result => {
                try {
                    const custId = result.id;
                    record.submitFields({
                        type: record.Type.CUSTOMER,
                        id: custId,
                        values: { isinactive: false }
                    });
                    log.debug('Updated', `Customer ${custId} reactivated.`);
                } catch (innerErr) {
                    log.error('Error updating customer', innerErr.message);
                }
            });
        } catch (e) {
            log.error('Error in scheduled script', e.message);
        }
    };
    return { execute };
});

🔹 Example 3: Send Reminder Emails

What this script does:

  • Finds open Sales Orders and emails an admin summary.
/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/search', 'N/email', 'N/runtime'], (search, email, runtime) => {
    const execute = () => {
        try {
            const soSearch = search.create({
                type: search.Type.SALES_ORDER,
                filters: [['status', 'anyof', 'SalesOrd:A']], // Pending Approval
                columns: ['tranid', 'entity']
            });

            const results = soSearch.run().getRange({ start: 0, end: 5 });

            let body = 'Open Sales Orders:\n';
            results.forEach(result => {
                body += `SO# ${result.getValue('tranid')} - Customer: ${result.getText('entity')}\n`;
            });

            if (results.length > 0) {
                email.send({
                    author: runtime.getCurrentUser().id,
                    recipients: 'admin@company.com',
                    subject: 'Pending Sales Orders Reminder',
                    body: body
                });
                log.debug('Success', 'Reminder email sent.');
            }
        } catch (e) {
            log.error('Error in scheduled script', e.message);
        }
    };
    return { execute };
});

🔹 Example 4: Chunk Processing with Governance Handling

What this script does:

  • Loops through results and checks usage limits, yielding control if running low.
/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/search', 'N/record', 'N/runtime'], (search, record, runtime) => {
    const execute = () => {
        try {
            const script = runtime.getCurrentScript();
            const results = search.create({
                type: search.Type.CUSTOMER,
                filters: [['isinactive', 'is', 'F']],
                columns: ['entityid']
            }).run().getRange({ start: 0, end: 100 });

            for (let i = 0; i < results.length; i++) {
                try {
                    const custId = results[i].id;
                    log.debug('Processing', `Customer ID: ${custId}`);
                    
                    // Example operation: update phone field
                    record.submitFields({
                        type: record.Type.CUSTOMER,
                        id: custId,
                        values: { phone: '555-123-0000' }
                    });

                    // Check governance usage
                    if (script.getRemainingUsage() < 100) {
                        log.debug('Governance', 'Rescheduling due to low usage.');
                        return; // exit early, will be rescheduled automatically
                    }
                } catch (innerErr) {
                    log.error('Error updating record', innerErr.message);
                }
            }
        } catch (e) {
            log.error('Error in scheduled script', e.message);
        }
    };
    return { execute };
});

🔹 Best Practices

  • Use submitFields() for lightweight updates (faster than record.load() + save()).
  • Always check remaining usage (runtime.getCurrentScript().getRemainingUsage()).
  • Split large jobs into batches or use Map/Reduce for big data.
  • Wrap each operation in try–catch to prevent one bad record from stopping the script.
  • Schedule during off-hours to reduce performance impact.

✅ Key Takeaway

Scheduled Scripts are the backbone of background automation in NetSuite. Use them for batch jobs, cleanup, reminders, and lightweight data updates. For heavy-lifting (thousands of records), move to Map/Reduce.

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