Return User and Session Information

The following sample shows how to use a Suitelet to write user and session information for the currently executing script to the response.

Note:

This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.

          /**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */

// This script writes user and session information for the currently executing script to the response.
define(['N/runtime'], function(runtime) {
    function onRequest(context) {
        var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
        var userRole = runtime.getCurrentUser().role;
        var currentSession = runtime.getCurrentSession();
        
        // Set the current sessions's scope
        currentSession.set({
            name: 'scope',
            value: 'global'
        });
        
        var sessionScope = runtime.getCurrentSession().get({
            name: 'scope'
        });
        
        log.debug('Remaining Usage:', remainingUsage);
        log.debug('Role:', userRole);
        log.debug('Session Scope:', sessionScope);
        
        context.response.write('Executing under role: ' + userRole
            + '. Session scope: ' + sessionScope + '.');
    }
    return {
        onRequest: onRequest
    };
}); 

        

General Notices