N/ui/message Module Script Sample

The following script sample demonstrates how to use the features of the N/ui/message module.

Create Confirmation, Information, Warning, and Error Messages

The following sample shows how to create messages for the four available types (confirmation, information, warning, and error).

Note:

This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.

Note:

To debug client scripts like the following, you should use Chrome DevTools for Chrome, Firebug debugger for Firefox, or Microsoft Script Debugger for Internet Explorer. For information about these tools, see the documentation provided with each browser. For more information about debugging SuiteScript client scripts, see Debugging Client Scripts.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

            /**
 * @NApiVersion 2.1
 */
define(['N/ui/message'], (message) => {
    let myMsg = message.create({
        title: 'My Title',
        message: 'My Message',
        type: message.Type.CONFIRMATION
    });
    myMsg.show({
        duration: 5000 // will disappear after 5s
    });

    let myMsg2 = message.create({
        title: 'My Title 2',
        message: 'My Message 2',
        type: message.Type.INFORMATION
    });
    myMsg2.show();
    setTimeout(myMsg2.hide, 15000); // will disappear after 15s

    let myMsg3 = message.create({
        title: 'My Title 3',
        message: 'My Message 3',
        type: message.Type.WARNING,
        duration: 20000
    });
    myMsg3.show(); // will disappear after 20s

    let myMsg4 = message.create({
        title: 'My Title 4',
        message: 'My Message 4',
        type: message.Type.ERROR
    });
    myMsg4.show(); // will stay up until hide is called.
}); 

          

You can see the outcome in the following screenshot:

N/ui/message Module Script Sample section

General Notices