SDF Installation SuiteScript File Example

The following example shows how to use SuiteScript with a SuiteCloud Development Framework (SDF) installation script. This installation script determines whether the Email Employee on Approvals preference in the General Settings of your target account is enabled

It performs the to the following tasks:

For information about SuiteScript API used and the runtime module, see:

The checkpreference_fail.js script example that follows is an SDF installation script that uses SuiteScript to ensure the Email Employee on Approvals preference is enabled in your target account before installing your SuiteCloud project. The script must be in your SuiteApp project, saved in the File cabinet as a .JS file, and referenced as a dependency in the manifest file. To run the script, there must be a corresponding SDF installation script record and deployment (sdfinstallationobject) in the project and you must also include a valid run tag in the project deploy file. For more information, see the following topics:

Important:

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

          /**
* @NApiVersion 2.1
* @NScriptType SDFInstallationScript
*/
define(['N/runtime'], (runtime) => {
    const run = (scriptContext) => {
        function checkPrerequisites() {
            if (!runtime.getCurrentUser().getPreference({name: 'emailemployeeonapproval'})) {
                throw 'The  Email Employee on Approvals preference  must be enabled. ' +
                'SDF INSTALL SCRIPT MESSAGE: Please enable the preference and try again.';
            }
        }
    }
    return {run}
}); 

        

This installation script checks in the General Preferences of your target account if the Email Employee on Approvals preference is enabled. The following image shows the preference as it appears in the NetSuite UI.

The General Preferences page with the Email Employee On Approvals field highlighted.

Related Topics

SDF Installation Script Example of Validating an Account Preference Before Installation
SDF Installation Script Object Example
Deploy File that Runs SDF Installation Script Example
Deployment Log Example

General Notices