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
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us
Home/ NetSuite Customization Guide: Fields, Forms, Workflows & Scripts/Custom Error Handling & Retry Framework for SuiteScript Integrations

Custom Error Handling & Retry Framework for SuiteScript Integrations

๐Ÿงฉ Custom Error Handling & Retry Framework for SuiteScript Integrations

Introduction

Even the best-written NetSuite integrations fail occasionally โ€” APIs time out, governance limits hit, or third-party services go down.
Instead of manually checking logs, you can build a Custom Error Handling Framework that captures every failure, logs it, and automatically retries based on rules.

This tutorial will walk you through creating a robust, reusable error-handling layer used in real-world integrations with Boomi, Shopify, and Salesforce.


๐Ÿ’ก Why a Centralized Error Framework?

ProblemWithout FrameworkWith Framework
API timeoutsManual debuggingAuto-retry with delay
Script failuresLost transaction dataLogged & queued for re-execution
Governance limitsScript haltsAutomatically resumes from checkpoint
Lack of visibilityHard to traceCentral error dashboard

๐Ÿงฑ Step 1: Create Custom Record โ€” โ€œIntegration Error Logโ€

Name: Integration Error Log
ID: customrecord_error_log

Field LabelIDTypeDescription
Integration Sourcecustrecord_err_sourceText/ListBoomi, Celigo, RESTlet
Record Typecustrecord_err_recordtypeText/ListSales Order, Invoice
Record IDcustrecord_err_recordidIntegerFailed record reference
Error Messagecustrecord_err_messageLong TextFull stack trace
Retry Statuscustrecord_err_retry_statusList (Pending, Retried, Failed)Current retry status
Retry Countcustrecord_err_retry_countIntegerNumber of attempts
Timestampcustrecord_err_timestampDate/TimeWhen the error occurred
Script Typecustrecord_err_script_typeTexte.g., Map/Reduce, RESTlet
Process IDcustrecord_err_processidTextUnique run identifier

โœ… Add permissions for Integration Admin or Developer roles only.


โš™๏ธ Step 2: Centralized Error Handling Utility

Create a shared module you can import into any SuiteScript.

/**
 * @NApiVersion 2.1
 * @NModuleScope Public
 */
define(['N/record', 'N/log'], (record, log) => {

    const logError = (source, recordType, recordId, errorObj, scriptType) => {
        try {
            const errRec = record.create({ type: 'customrecord_error_log', isDynamic: true });
            errRec.setValue('custrecord_err_source', source);
            errRec.setValue('custrecord_err_recordtype', recordType);
            errRec.setValue('custrecord_err_recordid', recordId);
            errRec.setValue('custrecord_err_message', JSON.stringify(errorObj.message || errorObj));
            errRec.setValue('custrecord_err_retry_status', 'Pending');
            errRec.setValue('custrecord_err_retry_count', 0);
            errRec.setValue('custrecord_err_script_type', scriptType);
            errRec.save();
        } catch (e) {
            log.error('Error Logging Failure', e);
        }
    };

    return { logError };
});

โœ… Usage: Import this module into any Map/Reduce, RESTlet, or Scheduled Script to catch and record errors.


๐Ÿง  Step 3: Add Try/Catch Blocks with Error Logging

Example in a Map/Reduce Script:

try {
   // process invoice
   record.submitFields({ type: 'invoice', id: invId, values: { memo: 'Processed' } });
} catch (e) {
   errorHandler.logError('Boomi', 'invoice', invId, e, 'Map/Reduce');
}

Every exception is automatically logged to your Integration Error Log.


๐Ÿ”„ Step 4: Automated Retry Script

Create a Scheduled Script or Map/Reduce to re-process failed records.

/**
 * @NApiVersion 2.1
 * @NScriptType ScheduledScript
 */
define(['N/search', 'N/record', 'N/log'], (search, record, log) => {
    const execute = () => {
        const results = search.create({
            type: 'customrecord_error_log',
            filters: [['custrecord_err_retry_status', 'is', 'Pending'], 'AND', ['custrecord_err_retry_count', 'lessthan', 3]],
            columns: ['internalid', 'custrecord_err_recordid', 'custrecord_err_source']
        }).run().getRange({ start: 0, end: 50 });

        results.forEach(r => {
            try {
                const recordId = r.getValue('custrecord_err_recordid');
                // Retry logic (e.g., re-call RESTlet or re-process transaction)
                log.audit('Retrying Record', recordId);
                record.submitFields({
                    type: 'salesorder',
                    id: recordId,
                    values: { custbody_retry_flag: true }
                });
                record.submitFields({
                    type: 'customrecord_error_log',
                    id: r.id,
                    values: {
                        custrecord_err_retry_status: 'Retried',
                        custrecord_err_retry_count: '@{custrecord_err_retry_count}+1'
                    }
                });
            } catch (err) {
                log.error('Retry Failed', err);
            }
        });
    };
    return { execute };
});

โœ… Retries only failed records with retry count < 3 โ€” prevents infinite loops.


๐Ÿงฎ Step 5: Dashboard Monitoring (Saved Search or SuiteAnalytics)

Saved Search: Integration Error Overview

  • Filters: custrecord_err_retry_status is not Success
  • Columns: Source, Record Type, Record ID, Error Message, Retry Count, Last Update
  • Highlighting:
    • Red โ†’ Failed
    • Yellow โ†’ Pending
    • Green โ†’ Retried

Add this to Home Dashboard for real-time tracking.


๐Ÿง  Step 6: Email / Slack Notifications

Workflow Notification (Simpler)

  • Trigger: On Create (if Retry Status = โ€œPendingโ€)
  • Action: Send Email โ†’ Integration Team

Advanced (Slack via RESTlet)

Send Slack alert on every failed integration:

https.post({
  url: 'https://hooks.slack.com/services/T0000/B0000/XXXX',
  body: JSON.stringify({ text: `๐Ÿšจ Integration Failed: ${errorMessage}` }),
  headers: { 'Content-Type': 'application/json' }
});

โšก Step 7: Governance & Performance Tips

ChallengeSolution
Too many logsAuto-delete records older than 90 days via Scheduled Script
Long stack tracesStore JSON payloads in File Cabinet
Concurrent retriesUse Map/Reduce for batch retry
High volumeSplit logs by integration source

๐Ÿงฉ Real-World Framework Workflow

1๏ธโƒฃ RESTlet / Script fails โ†’ Logs error in Custom Record
2๏ธโƒฃ Scheduled Script scans Pending logs daily
3๏ธโƒฃ Retries failed transactions (up to 3ร—)
4๏ธโƒฃ Success โ†’ Status = Retried; Failure โ†’ Status = Failed
5๏ธโƒฃ Dashboard + Email Alerts show live summary


๐Ÿงฐ Bonus: Custom Error Utility Snippet

Reusable utility for cleaner scripts:

function safeExecute(fn) {
    try { fn(); } 
    catch (e) { errorHandler.logError('RESTlet', 'transaction', null, e, 'Suitelet'); }
}

โœ… Keeps your core code readable and error-proof.


๐Ÿ“š Related Tutorials

  • ๐Ÿ‘‰ Integration Logging & Monitoring Dashboard
  • ๐Ÿ‘‰ SuiteScript Security & Governance Best Practices
  • ๐Ÿ‘‰ NetSuite Deployment & Version Control Strategy

โ“ FAQ

Q1. Can I automatically retry failed Boomi or Celigo integrations?
Yes โ€” send retry POST requests from the Scheduled Script back to your middleware endpoint.

Q2. Can this handle RESTlet and Map/Reduce together?
Absolutely โ€” log script type (Map/Reduce, RESTlet) and handle retries differently per type.

Q3. Can I notify users in NetSuite UI?
Yes โ€” use a custom Portlet showing recent โ€œFailed Integrations.โ€

Q4. What if error logging itself fails?
Wrap the logger in a try/catch with minimal dependencies (as above) so failure doesnโ€™t block your main process.


๐Ÿงญ Summary

With this framework, your NetSuite environment gains self-healing capability โ€” failed transactions are captured, reviewed, and retried automatically.
Instead of reactive debugging, you get proactive stability, visibility, and accountability for every integration.

This pattern transforms NetSuite into an enterprise-grade integration platform ready for high-volume, audit-safe operations.

Share
  • Facebook

Leave a ReplyCancel reply

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
  • 22 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