Skip to main content

$USERNAME (ObjectScript)

Contains the username for the current process.

Synopsis

$USERNAME

Description

$USERNAME contains the username for the current process. This can be in one of two forms:

  • The name of the current user; for example: Mary. This value is returned if multiple security domains are not allowed.

  • The name and system address of the current user; for example: Mary@jupiter. This value is returned if multiple security domains are allowed.

To allow multiple security domains, go to the Management Portal, select System Administration, Security, System Security, System-wide Security Parameters. Select the Allow multiple security domains check box. Changes to this setting apply to new invoked processes; changing it does not affect the value returned by the current process.

You cannot use the SET command or the NEW command to modify this value. However, NEW $ROLES also stacks the current $USERNAME value.

Commonly, the $USERNAME value is the username specified at connection time. However, if unauthenticated access is permitted, a user terminal or an ODBC client may connect to InterSystems IRIS without specifying a username. In this case, $USERNAME contains the string “UnknownUser”.

When a process is created using the JOB command, it inherits the same $USERNAME and $ROLES values as its parent process.

A username can be created using the SQL CREATE USER statement and deleted using the SQL DROP USER statement. A user password can be changed using the SQL ALTER USER statement. A user can have roles assigned to it, either by using the SQL GRANT statement, or by using system utilities to add a role to the user. You can access the list of roles assigned to the current process with the $ROLES special variable. A role can be revoked from a user using the SQL REVOKE statement.

$USERNAME is used in InterSystems SQL as the USER, CURRENT_USER, and SESSION_USER default field values.

You can return the username for the current process, or for a specified process, by invoking the $SYSTEM.Process.UserName()Opens in a new tab method.

Examples

The following example returns the username for the current process.

   WRITE $USERNAME

The following example returns the domain name for the current process.

   WRITE $PIECE($USERNAME,"@",2)

See Also

FeedbackOpens in a new tab