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:
-
The Email Employee on Approvals is a box in the UI so the
getPreference
method returns a Boolean value, indicating the value set for this preference in the target account. -
If the Email Employee on Approvals preference is not enabled, a message is thrown that will appear in scripting log and in IDE console and deployment of the SuiteApp fails.
-
If the Email Employee on Approvals preference is enabled, project deployment continues and you can run more scripts and tasks on the installation when needed.
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:
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.
