Using session parameters

This article describes standards that apply to session parameters. All of the listed recommendations are mandatory unless noted otherwise.

1.1. Session parameters are intended for storing values within a session. We recommend that you initialize the parameters in the session module (see section 2.1 later in this article) and that you use their values in session queries and data access restrictions.
Example session parameters:

  • CurrentUser. Type: CatalogRef.Users 
  • DataExchangeEnabled. Type: Boolean 
  • ClientWorkstation. Type: CatalogRef.ClientWorkstations

You can access session parameters using 1C:Enterprise script, as in the following example:

CurrentUserValue = SessionParameters.CurrentUser;

In this scenario the current user can read or write the value only if they are granted the corresponding right.

You can also use them in access restrictions, as in the following example:

WHERE Document.User = &CurrentUser

In the latter scenario the current user does not need the right to read the session parameter value.

1.2. We recommend that you do not use session parameters for storing values that are only needed on the client. In the client/server mode 1C:Enterprise stores session parameters on the server, so reading or changing them on the client requires making a server call, which increases the traffic between the server and the client.

We recommend that you use global variables of the managed application module (or the ordinary application module if your application runs in the ordinary mode). 

1.3 We recommend that you do not use session parameters for caching calculated values that can be reused by server algorithms. Instead, declare your function in a common server module with reusable return values, except scenarios where the function result calculation time in a module with reusable values is comparable to the cache clearing timeout.

Setting session parameters "on demand"

2.1. Do not initialize session parameters during the application startup because:

  • during the startup the platform does not read all of the session parameters from the configuration code;
  • the application algorithms might include explicit deletion of session parameter values using 1C:Enterprise script tools.

The correct method of setting session parameter values is setting them "on demand" in the SessionParametersSetting handler of the session module. In other words, session parameters must be initialized when they are accessed for the first time.

Example of setting session parameters "on demand":

Procedure SetSessionParameters(SessionParametersNames)
 If SessionParametersNames = Undefined Then
  // Session parameter initialization at startup (SessionParametersNames = Undefined)
  // Assign values to session parameters that can be initialized at startup
  // Session parameter initialization "on demand"  
  // If initialization of multiple session parameters requires accessing
  // the same set of data, initialize all of them at once.
  // To avoid duplicate initializations, names of the initialized
  // session parameters are stored to the InitializedParameters array.
  InitializedParameters = New Array;
  For Each ParameterName FROM SessionParametersNames Do
   SetSessionParameterValue(ParameterName, InitializedParameters);


// Set session parameter values and write the names of the initialized parameters
// to the InitializedParameters parameter. 
// Parameters
//  ParameterName - String - name of the session parameter to be initialized.
//  InitializedParameters - Array - array that stores names of initialized parameters.
Procedure SetSessionParameterValue(Val ParameterName, InitializedParameters)
 // If the ParameterName parameter is already initialized in this SetSessionParameters
 // call, then return.
 If InitializedParameters.Find(ParameterName) <> Undefined Then
 If ParameterName <> "CurrentUser" Then
   SessionParameters.CurrentUser = <value>;
   SessionParameters.<another session parameter> = <value>;
   InitializedParameters.Add("<another session parameter>");


Next page: Using subsystems

See also:

Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.