GetUserSession

Description: The module this function returns is useful for accessing session-specific variables. The function will traverse the call tree to find the session that called it.
Returns: A session module instance.
Usage: Script or steady state.
Function Groups: Basic Module,  Variable
Related to: ParentWindow
Format: \GetUserSession([DefaultToRootSession])[\QueryVariable]
Parameters:  
DefaultToRootSession
Optional Boolean. If TRUE (the default value) then if a valid session is not found, this function will return the Display Manager's root session. (That is, the one pertaining to the actual running application as opposed to any remotely established session.)
If set FALSE, then Invalid will be returned if a valid session is not found.
QueryVariable
Optional. The name of a variable to be queried. Examples include, but are not limited to:
\IsRootSession
\AppTitle
\CurrentWinInst\PageInstance
Comments:

This routine walks up the caller's call tree, looking for a variable named "_UserSession_", then returning the context containing that variable. In none is found, then the Display Manager's root session will be return unless the optional parameter is set to FALSE.

GetUserSession is also useful for launching dialogs in the scope of a particular user session. This means that a tag or service which is not associated with any particular user can cause a dialog to open on a particular VIC session.

Note that the public variable, IsEditing, is obsolete. In place of GetUserSession\IsEditing, new code should use ParentWindow()\Editing.

Examples:

Launch a dialog in the scope of a session:

If OpenDialog Idle;
[
  Session = \GetUserSession();
  Launch("Dialog", Self() { Parent }, Session { Caller });
]