Client Script Role Restrictions
Client scripts follow the permissions set up in your NetSuite account. You'll get an error if you try to run a client script to access a record without the right permissions.
The following client script attaches to a custom sales order form and executes when the fieldChanged entry point is triggered:
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/search'],
function(search) {
function getSalesRepEmail(context) {
var salesRep = context.currentRecord.getValue({
fieldId: 'salesrep'
});
var salesRepEmail = search.lookupFields({
type: 'employee',
id: salesRep,
columns: ['email']
});
alert(JSON.stringify(salesRepEmail));
}
return {
fieldChanged: getSalesRepEmail
}
});
If you're logged in as an administrator, you'll get the alert when you load the sales order with this form. If you are logged in with a role that does not have permission to view/edit Employee records, you receive an error when you select the Sales Rep field.
To avoid this error, consider the following:
-
Consider the types of users who will be using your custom form and running the script.
-
Consider which record types users can't access. If everyone running the script needs access to those records, you might need to update their permissions (if you're an administrator).
-
Consider rewriting the script to only use records that everyone can access.
-
Consider writing the script as a user event script, and set the Execute As Admin preference on the Script Deployment page. Keep in mind that alerts only work in client scripts, not user event scripts. For more information about user event scripts, see SuiteScript 2.x User Event Script Type.