N
NetSuite Input Dialog
InputDialog
A utility class extending NetSuite's N/ui/dialog module with the ability to capture user input, optionally persisting it directly to a predefined field on the form upon submission. The source code and an explanation of the solution can be found on the NetSuite Insights blog.
InputDialog.create([options], [success], [failure])
Method Description | Creates an input dialog with the specified options. |
Returns | void |
Supported Script Types | Client scripts |
SuiteScript Version | 2.0 (for compatibility) |
Governance | None |
Module | Extends N/ui/dialog |
Module Scope | Same Account |
Parameters
Parameter | Path | Type | Required/Optional | Description | Since |
---|---|---|---|---|---|
options | N/A | Object |
Optional | Configuration options for the input dialog. | 1.0.0 |
options.title | string |
Optional | The dialog title. Defaults to an empty string. | 1.0.0 | |
options.message | string |
Optional | Text to be displayed about the input field. Defaults to an empty string. | 1.0.0 | |
options.buttons | Object[] |
Optional | A list of buttons to be included in the dialog. Each item in the button list must be an object that contains a label and a value property. By default, a single button with the label OK and the value 1 is used. | 1.0.0 | |
options.textarea | Object |
Optional | The configuration for the input text area. If not specified, default values as specified below are used. | 1.0.0 | |
options.textarea.rows | Object |
Optional | The input text area's default height expressed in rows. Defaults to 5. | 1.0.0 | |
options.textarea.cols | Object |
Optional | The input text area's default width expressed in columns. Defaults to 40. A value above 50 is NOT recommended. | 1.0.0 | |
options.textarea.isMandatory | Object |
Optional | Indicates whether user input is mandatory. If true and the user presses an action button without entering any input, an alert popup will be shown and the input dialog will stay open. Defaults to false. | 1.0.0 | |
options.textarea.caption | Object |
Optional | The caption to show above the input text area. Defaults to 'Input field *' if isMandatory = true; omitted otherwise. | 1.0.0 | |
options.textarea.initialValue | Object |
Optional | The initial value to be displayed in the input text area. Defaults to an empty string. | 1.0.0 | |
options.textarea.fieldId | Object |
Optional | The ID of the field on the current page to which the user input should be written upon closing the Input dialog using any of the action buttons. If specified, in addition to writing the text to this field, the text will still be passed to the success callback function if provided. | 1.0.0 | |
options.textarea.actionButtons | int[] |
Optional | A list of buttons (value properties only) that will trigger validation and persisting the input. Defaults to all buttons added to the input dialog. Using this option, the cancel button can be excluded as an action button, enabling it to be used to close an input dialog without providing input. | 1.0.0 | |
success | N/A | function |
Optional | A callback function to be executed (asynchronously) when the dialog is closed. It will be passed two parameters: (1) The value of the button pressed and (2) the input entered by the user. E.g. success(result, value)
|
1.0.0 |
failure | N/A | function |
Optional | A callback function to be executed (asynchronously) if anything goes wrong. It simply forward whatever NetSuite's native dialog.create() passes into the catch portion of the Promise object. E.g. failure(reason)
|
1.0.0 |
Errors
Same as for N/ui/dialog.create(options)
. See official documentation here (NetSuite login required).
Examples
The following example illustrate common usage of the input dialog module. The examples assume the module is loaded in your client script as nsiInputDialog
and the following callback functions are defined:
function failure(reason) {
console.log('Failure: ' + reason);
}
function success(result, value) {
alert('Input dialog closed by clicking button ' + result + ' | value: ' + value);
// Do something with the actual result here.
}
Example 1 (trivial): Create an input dialog with no options
nsiInputDialog.create(null, success, failure);
Example 2 (basic): Create an input dialog with optional input (basic example)
var options = {
title: 'Input Dialog',
message: 'Please enter your approval notes below:',
textarea: {
initialValue: 'Approved',
caption: 'Approval Notes',
}
};
nsiInputDialog.create(options, success, failure);
Example 3 (advanced): Create an input dialog with mandatory input and persistence to field
var options = {
title: 'Input Dialog',
message: 'Please enter your rejection reason below:',
buttons: [{
label: 'Reject',
value: 1
},{
label: 'Cancel',
value: 2
}],
textarea: {
rows: 6,
cols: 48,
isMandatory: true,
caption: 'Rejection Reason',
fieldId: 'memo',
actionButtons: [1]
}
};
nsiInputDialog.create(options, success, failure);