ANS-1630 · SUITESCRIPT DEVELOPMENT
How Does ‘Execute as Role’ Affect User Context in NetSuite SuiteScript?
The 'Execute as Role' setting in NetSuite SuiteScript deployments governs script permissions, not the current user's role.
Short answer
The 'Execute as Role' field on a NetSuite script deployment dictates the permissions the script operates under, but it does not alter the current user's role as returned by the N/runtime module. The context object consistently reflects the actual user initiating the script, irrespective of the deployment's execution role.
Scenario
NetSuite developers often configure script deployments with an 'Execute as Role' to manage permissions. A common question arises regarding whether this setting influences the role information retrieved from the script's execution context, leading to potential confusion about user identity versus script privileges.
Solution
Regardless of the role specified in the 'Execute as Role' field on a script deployment, the role property within the script's execution context remains unaffected. When retrieving user role information using the SuiteScript 2.x N/runtime module, the system will consistently return the role of the current user who initiated the script, not the role configured in the deployment's 'Execute as Role' setting. For example, to get the current user's role:
var currentUser = runtime.getCurrentUser();
var userRole = currentUser.role;The 'Execute as Role' field primarily functions to define the permissions under which the script itself operates. This ensures the script has the necessary access to records and operations, independent of the initiating user's specific role, without altering the identity of the user executing the script.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
