The N/runtime module gives your SuiteScript access to the current execution environment β who is running the script, what context the script is running in, what the current account and script parameters are, and how much governance is remaining.
Getting Current User Info
define(["N/runtime", "N/log"], (runtime, log) => {
const user = runtime.getCurrentUser();
log.debug("User ID", user.id);
log.debug("User Name", user.name);
log.debug("User Role", user.role);
log.debug("Subsidiary", user.subsidiary);
return {};
});
Checking Execution Context
const context = runtime.executionContext;
if (context === runtime.ContextType.USER_INTERFACE) {
log.debug("Running in UI", context);
} else if (context === runtime.ContextType.SCHEDULED) {
log.debug("Running as scheduled script", context);
}
Checking Governance Usage
const script = runtime.getCurrentScript();
const remaining = script.getRemainingUsage();
log.debug("Remaining governance", remaining);
if (remaining < 100) {
log.error("Low governance", "Stopping to avoid timeout");
return;
}
Reading Script Parameters
const script = runtime.getCurrentScript();
const folderId = script.getParameter({ name: "custscript_folder_id" });
log.debug("Folder ID param", folderId);