Scope: managed applications, mobile applications, and ordinary applications.
1.1. When developing a managed application, control the number of server procedure and function calls from the client code (server calls). In some cases, you also need to control the data being transferred between the client and the server (traffic).
The aggregate number of server calls includes the following:
-
Server calls made by 1C:Enterprise platform.
-
Calls made from the configuration client code (a deviation made by the configuration towards the platform).
Generally, when you design client/server interactions in the configuration, note that no single user action in the configuration client code must require additional server calls. Any exceptions must be reasonable.
1.2. For the slow connection mode, optimize both the number of calls and volume of data being transferred between the client and the server (traffic). We recommend that you debug client/server interactions in this mode in the mode of simulation of server call latency.
Below you can see standard user actions and recommendations for client/server interactions.
Starting client applications
2.1. In the simplest case, a configuration code executed upon a client application startup must not cause server calls. If you need to get server data:
-
We do not recommended that you call server procedures and functions directly from the application module code, managed application module, or external connection module.
-
Correct example: within a single server call transfer all parameters required to start an application.
If it is required to request client application startup parameters from the server from multiple client code locations, place this function in a common server module with repeated use of return values. If this function is called for the first time, a single server call is made. After that, the received value is automatically cached by the platform on the client for all repeated calls of this function.
Example:
// StandardSubsystemsOverridable common server module fragment with repeated use of return values
Function ClientRunParameters()
Parameters = New Structure();
Parameters.Insert("FileInfobase", Common.FileInfobase());
// Initialization of other parameters required on the client to start the application
// Parameters.Insert(parameter name, parameter value);
Return Parameters;
EndFunction
Example of a client code that uses the ClientRunParameters function:
FileInfobase = StandardSubsystemsOverridable. ClientRunParameters().FileInfobase;
If FileInfobase Then
// This event processing in client code
//…
See also: Using values affecting client application behavior
Opening managed forms
3.1. If a form is opened from code, open it with a single call using the OpenForm global context method. If you use 1C:Enterprise 8.2 platform or earlier versions, you can also use OpenFormModal. To pass parameters to the form, use the Parameters parameter of these methods.
3.2. Whenever a form is opened, avoid server calls from the form module code in the form client event handlers, such as OnOpen and OnReopen. If you need to access server data from these handlers, place this data in the form attributes in OnCreateAtServer.
Incorrect:
ProxyServerSetting = ServerModule.ProxyServerSetting();
OpenForm("CommonForm.ProxyServerParameters", New Structure("Settings", ProxyServerSetting));
Correct example:
OpenForm("CommonForm.ProxyServerParameters");
Get the constant value in the OnCreateAtServer handler of the ProxyServerParameters form.
Executing local commands of managed forms
4.1. Make sure that execution of a local command results in a single server call only.
- If a command executes client operations only (opens a new form, sets a filter in a list, changes appearance, and so on), all the data required to execute the command must be preliminary passed to the client. We recommend that you prepare this data in advance in the OnCreateAtServer form event handler and place it in the form attributes.
Example:
When goods are selected from the list, it is required to restrict product group selection for users. Whenever a user attempts to select a product group, the application must display a warning. It is incorrect to call a separate server function to check whether the selected product item is a group. Add the IsFolder attribute to a value table related to a form list field. Fill in the attribute in the OnCreateAtServer form event handler. In this case, check on the client is performed without additional server call and is as follows:
CurrentRow = Item.CurrentData;
If CurrentRow.IsFolder Then
Message = New UserMessage();
Message.Text = NStr("en = "Group selection is restricted'");
Message.Message();
Return;
EndIf;
- If a command is related to business logic, which can be processed on the server only, it must be executed within a single server call.
Selection from catalogs
4.2. Generally, when selecting from a catalog, only one server call from code is allowed. Call of the OpenForm or OpenFormModal global context method results in the server call.
4.3. If after selection from a catalog it is required to execute the business logic, which can be processed on the server only, you can execute it within one additional server call.
Executing global commands
5.1. Upon executing a global command, only one server call from code is allowed. If a command opens a form, a call must be made upon calling the OpenForm or OpenFormModal global context method.
Executing report generation commands
6.1. No additional server calls from the configuration code are allowed upon executing a report generation command.
In particular, when opening a report form, avoid server calls from the form module code in the form client event handlers, such as OnOpen and OnReopen.
For example, it is incorrect to generate a report that uses a data composition system from the OnOpen form handler:
&AtClient
Procedure OnOpen(Cancel)
OutputReport();
EndProcedure
&AtServer
Procedure OutputReport()
// Code to generate the report…
EndProcedure
Correct example:
- Open a report form with the GenerateOnOpen = True.
- Set the GenerateOnOpen form parameter to True in the OnCreateAtServer handler.
Selecting items
7.1. During client/server interaction upon selecting items, it might be required to pass the selected item list between the object form and the selection form. Data size to be passed can be rather large.
In this case, we do not recommend that you pass potentially large size of data as a selection form parameter. Potentially, a large size of data stored in the selection form in the FormDataCollection type parameter can be not full on the client due managed form optimization. As a result, form data from the server is additionally read to pass the parameter.
7.2. To optimize data passing between object forms and selection forms, we recommend that you use a temporary storage. The storage must be read and written on the server.
Have a look at how a selection form is used in the following example. We need to select the Goods catalog items and place them in the Goods tabular section in the GoodsConsumption document. The example is from the demo configuration on 1C:Enterprise platform.
Whenever a selection form is opened from the client code, no more than two server calls are allowed. For this purpose, a local command for opening a selection form in the GoodsConsumption document form module transfers a list of goods from the tabular section to a temporary storage (first call) and opens a selection form (second call) by passing the temporary storage address:
&AtClient
Procedure SelectionCommandHandler()
GoodsAddressInStorage = PutGoodsInStorage();
SelectionParameters = New Structure("DocumentGoodsAddress, PricesKind, Warehouse", GoodsAddressInStorage, Object.PricesKind, Object.Warehouse);
SelectionForm = OpenForm("Document.GoodsConsumption.Form.SelectionForm", SelectionParameters, IsObject);
EndProcedure
&AtServer
// The function transfers a list of goods to a temporary storage and returns an address
Function PutGoodsInStorage()
Return PutInTempStorage(Object.Goods.Unload(,"Goods,Price,Count"), UUID);
EndFunction
The selection form receives a list of goods selected from the temporary storage in the OnCreateAtServer handler:
&AtServer
Procedure OnCreateAtServer(Cancel, StandardProcessing)
DocumentGoodsAddress = Parameters.DocumentGoodsAddress;
Goods.Load(GetFromTempStorage(DocumentGoodsAddress));
…
EndProcedure
Whenever a selection form is closed, no more than two server calls are allowed. When being closed, the selection form places a list of selected goods in the temporary storage (first call):
&AtClient
Procedure OKExecute()
WriteSelectionToStorage();
FormOwner.ProcessSelection();
Close();
EndProcedure
&AtServer
Procedure WriteSelectionToStorage()
PutInTempStorage(Goods.Unload(), DocumentGoodsAddress);
EndProcedure
The document form restores a list of goods from the temporary storage (second server call):
&AtClient
Procedure ProcessSelection() Export
GetGoods FromStorage(GoodsAddressInStorage);
EndProcedure
&AtServer
Procedure GetGoodsFromStorage(GoodsAddressInStorage)
Object.Goods.Load(GetFromTempStorage(GoodsAddressInStorage));
EndProcedure