Good user interfaces guide people through their work and confirm important decisions before they happen. The N/ui/dialog module in SuiteScript 2.x lets developers generate modal pop-up windows directly in the browser, giving Client Scripts and Suitelets a clean, native way to present information and capture user choices.
What the N/ui/dialog Module Does
The module produces modal dialogs that overlay the current page and require the user to respond before continuing. Because these dialogs use NetSuite’s own styling, they feel consistent with the rest of the interface and work reliably across the supported browsers without any custom HTML or CSS.
Alert, Confirm, and Create Dialogs
The dialog.alert() method shows a simple message with a single acknowledgement button, ideal for surfacing warnings or status updates. The dialog.confirm() method presents OK and Cancel options so you can branch your logic based on the user’s response. For more advanced needs, dialog.create() builds a custom modal with configurable buttons and message content.
Working with Promises
Dialog methods return promises that resolve when the user makes a choice. This asynchronous pattern means your script can pause for input without freezing the page, then continue once the dialog closes. Handling the resolved value lets you run different logic depending on which button the user clicked.
Code Examples
Example 1 โ Showing a simple alert:
require(['N/ui/dialog'], function(dialog) {
dialog.alert({
title: 'Record Saved',
message: 'The record was saved successfully.'
});
});
Example 2 โ Asking for confirmation and handling the response:
require(['N/ui/dialog'], function(dialog) {
dialog.confirm({
title: 'Delete Line',
message: 'Are you sure you want to remove this line?'
}).then(function(result) {
if (result) {
console.log('User confirmed');
} else {
console.log('User cancelled');
}
});
});
Example 3 โ Building a custom dialog with dialog.create():
require(['N/ui/dialog'], function(dialog) {
var options = {
title: 'Choose an Action',
message: 'How would you like to proceed?',
buttons: [
{ label: 'Approve', value: 1 },
{ label: 'Reject', value: 2 }
]
};
dialog.create(options).then(function(value) {
log.debug('Button clicked', value);
});
});
Best Practices
Reserve modal dialogs for moments that genuinely require attention, since overusing them disrupts the workflow. Keep titles and messages short and action-oriented so users understand the decision quickly. Always handle both the confirm and cancel paths, and remember that dialogs run in the client context, so they belong in Client Scripts and Suitelet client logic rather than server-side scripts.
Used thoughtfully, the N/ui/dialog module helps you build NetSuite customizations that feel polished and intuitive, guiding users through critical actions with confidence.
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply