Compilation directives: Differences between &AtClient, &AtServer and &AtServerNoContext


Since the release 8.2 of the 1C:Enterprise platform, compilation directives can define whether a task should be executed client-side or server-side. This slightly complicates the development process, but helps developers to create faster and better optimized 1C configurations, since the workload of all complex tasks can be transferred to the server. This client-server separation means that some functionality is available on the client and some on the server. Information about which objects and features are available client-side or server-side can be obtained from Syntax Assistant.

The client and server communicate with each other using server calls to complete procedures that require database-related actions. Understanding the basic mechanism behind this communication is necessary to design an efficient solution that can respond to client queries, especially with a certain network bandwidth.

In this article, differences between the most common compilation directives will be explained and demonstrated with a practical example:

  • &AtClient: Code marked with this directive is executed on the client computer (a computer operated by the user) and with the current user's permissions. Any files created by &AtClient procedures or functions are stored on the client computer.

    When using &AtClient, keep in mind that client computer is typically slower than server, resulting in slower execution of your code.

    There are several code limitations for &AtClient. For example, &AtClient procedures or functions cannot access the DBMS. This means both database queries and references to access or modify an object are unavailable. To do that, a &AtClient procedure needs to call another procedure with &AtServer or &AtServerNoContext directive.

  • &AtServer: Code marked with this directive is executed on the 1C server (in the rphost process that handles client requests and interacts with the database server). Any files created by the &AtServer procedures are stored on the server and can only be saved to folders to which the 1C agent user has write access. Functions or procedures with &AtServer directive are free to use queries, access predefined data and object details through the reference.

    This directive is the most functional of the three, but potentially the most resource-intensive too.

  • &AtServerNoContext: A managed form (e.g. item form, list form, document form) is represented in the backend as an XML file describing the location of elements and values of form details. The more elements on the form, the more data stored in the form details. When a piece of code with the &AtServer directive is called, that form XML is sent from the client computer to the server. This XML is what is meant by context.
    The disadvantage of using &AtServer is that the entire XML file is passed to the server even when a small section of the form needs to be modified. It may sometimes be required to transfer quite large files that may take even minutes to process. In contrast, when a procedure or function is called without context (&AtServerNoContext), the function does not have access to the form details and cannot read or modify them. Especially when a function does nothing with the form, using this directive makes the configuration run much faster since data transfer is reduced significantly.

    DirectivesComparison.png

Quick comparison

DirectiveForm Data AccessDatabase AccessWorkload
&AtClientClient side
&AtServerServer side
&AtServerNoContextServer side

Basic example

DirectivesExample.png
Several lines are commented out since objects in these lines are not accessible with the given directive.

There are two other compilation directives—&AtClientAtServer and &AtClientAtServerNoContext—that are not commonly used but can be useful in certain cases.
For more details on each compilation directive, see 4.8.1. Procedures and functions execution.

Icon/Social/001 Icon/Social/006 Icon/Social/005 Icon/Social/004 Icon/Social/002