ANS-0563 · SUITESCRIPT DEVELOPMENT

How to Identify the Current User ID in NetSuite SuiteScript 2.x

Understand how NetSuite identifies authenticated and unauthenticated users within SuiteScript, particularly for web-facing applications.

Short answer

In NetSuite SuiteScript 2.x, the current user's internal ID can be retrieved using runtime.getCurrentUser().id. For unauthenticated access, such as 'Available without Login' Suitelets or online forms, a distinct identifier (often a negative integer) is typically returned, indicating that a user cannot be properly identified by NetSuite.

Scenario

Developers often need to programmatically identify the user interacting with a NetSuite script, whether for logging, personalization, or access control. This is particularly relevant when building Suitelets or online forms that may be accessed by both authenticated NetSuite users and external, unauthenticated visitors.

Solution

To retrieve the internal ID of the current user in NetSuite SuiteScript 2.x, utilize the runtime module. The getCurrentUser() method provides an object containing user details, including their internal ID.

javascriptvar currentUser = runtime.getCurrentUser();var userId = currentUser.id;

The userId variable will hold the integer value of the current user (for example, 195, 25, 21). For scenarios where a user has not authenticated to NetSuite, such as when accessing 'Available without Login' Suitelets or online forms, a distinct integer value is typically returned to indicate that the user cannot be properly identified by NetSuite. This value is often a negative integer, serving as a placeholder for unidentifiable access.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant