GlideSession - Scoped

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 10분
  • The scoped GlideSession API provides methods to find information about the current session.

    There are no constructors for creating an instance of a scoped GlideSession object. Instead, use the getSession() method of the scoped GlideSystem API.

    Scoped GlideSession - getClientData(String paramName)

    Retrieves a session client value previously set with putClientData().

    Use this method to retrieve data values that were set using the putClientData() method.

    표 1. Parameters
    Name Type Description
    paramName String Name of the client data to retrieve.
    표 2. Returns
    Type Description
    String Client data.
    var session = gs.getSession();
    session.putClientData('test1', 'Harry');
    var clientData = session.getClientData('test1');
    gs.info(clientData);

    Output:

    Harry

    Scoped GlideSession - getClientIP()

    Returns the client IP address.

    표 3. Parameters
    Name Type Description
    None
    표 4. Returns
    Type Description
    String IP address.
    var session = gs.getSession();
    var addr = session.getClientIP();
    gs.info(addr);

    Output:

    50.59.164.97

    Scoped GlideSession - getCurrentApplicationId()

    Returns the application currently selected in the application picker.

    This method requires admin privileges.

    표 5. Parameters
    Name Type Description
    None
    표 6. Returns
    Type Description
    String Currently selected application.
    var session = gs.getSession();
    var appID = session.getCurrentApplicationId();
    gs.info(appID);

    Output:

    ce05b9f32b840200c5244f74b4da1501

    Scoped GlideSession - getCurrentDomainID()

    Returns the sys_id of the current domain for the logged-in user session.

    The identifier that is returned depends on the domain type and the instantiation of that domain.
    • If the user is configured in the global domain, and does not use the domain picker to switch domains, the method returns null.
    • If the user uses the domain picker to switch to the global domain, the method returns the string "global".
    • For all other domains, the method returns the sys_id of that domain.
    표 7. Parameters
    Name Type Description
    None
    표 8. Returns
    Type Description
    String Sys_id of the session domain of the current logged-in user. This is the same information that appears in the domain picker.

    This example shows the current sys_email record's domain being set to the user's session domain, if the user domain is global or null.

    // Set domain based on parent record's domain
    setDomain();
    
    // If the domain is global, set to user's domain
    if (current.sys_domain == 'global' || current.sys_domain.nil())
       current.sys_domain = gs.getSession().getCurrentDomainID();
    
    function setDomain() {
       if (current.target_table.nil())
          return;
    
       var d = new GlideRecord(current.target_table);
       if (!d.isValid())
          return;
    
       if (!d.get('sys_id', current.instance))
          return;
    
       if (typeof(d.sys_domain) == 'object')
          current.sys_domain = d.sys_domain;
    

    Scoped GlideSession - getLanguage()

    Returns the session's language code.

    표 9. Parameters
    Name Type Description
    None
    표 10. Returns
    Type Description
    String Session's language code.
    var session = gs.getSession();
    var language = session.getLanguage();
    gs.info(language);

    Output:

    en

    Scoped GlideSession - getSessionToken()

    Returns the session token.

    표 11. Parameters
    Name Type Description
    None
    표 12. Returns
    Type Description
    String Session token.
    var session = gs.getSession();
    var token = session.getSessionToken();
    gs.info(token);

    Output:

    4284b5372b840200c5244f74b4da15f2c3476cf7fcb6572afa4ef9d5e6d307a5fd9e1da7

    Scoped GlideSession - getTimeZoneName()

    Returns the name of the session's time zone.

    표 13. Parameters
    Name Type Description
    None
    표 14. Returns
    Type Description
    String Name of the session's time zone.
    var session = gs.getSession();
    var zoneName = session.getTimeZoneName();
    gs.info(zoneName);

    Output:

    US/Pacific

    Scoped GlideSession - getUrlOnStack()

    Returns the URL on the stack. Returns null if the stack is empty.

    표 15. Parameters
    Name Type Description
    None
    표 16. Returns
    Type Description
    String URL on the stack. Returns null if the stack is empty.
    var session = gs.getSession();
    var URL = session.getUrlOnStack();
    gs.info(URL);

    Output: line breaks added for clarity.

    sys_app.do?sys_id=ce05b9f32b840200c5244f74b4da1501&sysparm_goto_url=sys_app.do
    %3Fsys_id%3Dce05b9f32b840200c5244f74b4da1501

    Scoped GlideSession - isImpersonating()

    Returns true if the user is impersonating another user.

    표 17. Parameters
    Name Type Description
    None
    표 18. Returns
    Type Description
    Boolean Flag that indicates the user is impersonating another user.
    Possible values:
    • true: User is impersonating.
    • false: User isn't impersonating.
    var isImpersonator = gs.getSession().isImpersonating();
    gs.info(isImpersonator);

    Scoped GlideSession - isInteractive()

    Returns true if the session is interactive.

    An interactive session is one that involves an end-user interacting with a user interface that then retrieves information from a server. An example of this type of session is when a user logs in using the log-in screen or uses a form to query a data store. A non-interactive session is one that only involves programmatic interaction with a server such as a SOAP request to retrieve data.

    표 19. Parameters
    Name Type Description
    None
    표 20. Returns
    Type Description
    Boolean Flag that indicates whether the session is interactive.
    Possible values:
    • true: Session is interactive.
    • false: Session isn't interactive.
    var interActive = gs.getSession().isInteractive();
    gs.info(interActive);

    Scoped GlideSession - isLoggedIn()

    Returns true if the user is logged in.

    표 21. Parameters
    Name Type Description
    None
    표 22. Returns
    Type Description
    Boolean Flag that indicates whether the user is logged in
    Possible values:
    • true: User is logged in.
    • false: User isn't logged in.
    var session = gs.getSession();
    var loggedIn = session.isLoggedIn();
    gs.info(loggedIn);

    Output:

    true

    Scoped GlideSession - putClientData(String paramName, String paramValue)

    Sets a session client value that can be retrieved with getClientData(). This method is used in a server side script that runs when a form is created.

    표 23. Parameters
    Name Type Description
    paramName String Name of the client data to set.
    paramValue String Value of the client data.
    표 24. Returns
    Type Description
    void
    var session = gs.getSession();
    session.putClientData('test1', 'Harry');
    var clientData = session.getClientData('test1');
    gs.info(clientData);

    Output:

    Harry