ANS-0987 · SUITESCRIPT DEVELOPMENT

How to Implement Custom Yes/No Dialogs in NetSuite Save Records

Learn how to manage asynchronous user interactions during record saves in NetSuite, leveraging best practices for dialog modules.

Short answer

To implement custom Yes/No dialogs during a NetSuite record save, especially when using external libraries, a common workaround involves pausing script execution by returning false from saveRecord. A global variable tracks user interaction, and upon selection, a programmatic save action is triggered. For modern NetSuite development, consider using the N/ui/dialog module for robust UI interactions.

Scenario

NetSuite's native 'confirm' dialogs present "OK/Cancel" options, which may not align with specific user experience requirements for "Yes/No" choices. When custom dialogs are introduced, particularly within the saveRecord function, the asynchronous nature of these dialogs can cause the record to save before the user makes a selection, leading to unintended behavior.

Solution

The challenge of implementing custom "Yes/No" dialogs in NetSuite, especially within the saveRecord function, arises because external dialog libraries do not inherently pause script execution. While NetSuite's N/ui/dialog module is the recommended approach for modern UI interactions, if an external library is utilized, a specific workaround can manage asynchronous dialogs during record saves.While direct importing of external CSS files into a NetSuite page is not natively supported in the same manner as standard web development, CSS can be embedded within Suitelets or custom HTML fields to style custom dialogs. When considering external JavaScript libraries for custom dialogs, compatibility with NetSuite's jQuery version may vary and requires thorough testing.To manage asynchronous dialogs during a record save using an external library, the following steps outline a common pattern:

  1. Initialize a global variable to track whether a user has interacted with the custom dialog.

  2. Within the saveRecord function, if the global variable indicates no prior interaction, generate the custom dialog and immediately return false. This action temporarily halts the record save process, creating the illusion of paused execution for the user.

  3. Upon the user's selection within the custom dialog, update the global variable to reflect interaction. Subsequently, programmatically trigger the NetSuite save action. This ensures that when the saveRecord function is re-executed, the dialog is not regenerated, and the save process proceeds normally. Note that direct DOM manipulation of standard NetSuite buttons for this purpose is not supported and may lead to breaking changes.The following code demonstrates this pattern using an example external library:

javascriptvar notyClicked = false;function saveRecord_generatePopup(){    if (!notyClicked) {        // generate noty popup        generateNotyAlert();        return false;    }    // your normal code on save    return true;}function generateNotyAlert(){    var n = noty({        text: 'Would you like to do something?',        type: 'alert',        dismissQueue: false,        layout: 'topCenter',        theme: 'defaultTheme',        animation: {            open: {                height: 'toggle'            },            close: {                height: 'toggle'            },            easing: 'swing',            speed: 0        },        buttons: [{            addClass: 'btn btn-primary',            text: 'Yes',            onClick: function($noty){                $noty.close();                notyClicked = true;                // Programmatically trigger NetSuite save action.                // Direct DOM manipulation of standard NetSuite buttons is not supported.            }        }, {            addClass: 'btn btn-danger',            text: 'No',            onClick: function($noty){                $noty.close();                notyClicked = true;                // Programmatically trigger NetSuite save action.                // Direct DOM manipulation of standard NetSuite buttons is not supported.            }        }]    });}

To integrate an external library like the one demonstrated, attach the necessary files to the script record in the specified order:

  • jquery.noty.js
  • Layout file (e.g., topCenter.js)
  • Theme file (e.g., default.js, often referred to as defaultTheme)

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant