Scope: managed applications, mobile applications.
1. To open forms, employ the OpenForm global context method. For 1C:Enterprise platform version 8.2 and earlier, you can also use the OpenFormModal method. It is not recommended to employ the GetForm method to get and open forms.
By following this best practice, you will:
- Increase the code robustness, since the application interface and the form's internal implementation are separated.
- Keep the code consistent with other 1C:Enterprise applications.
Also, OpenForm initializes the form on the server, with the OnCreateAtServer handler. Such approach ensures that all initialization code of the form is executed in the same place, which eliminates unwanted client-to-server calls from the code between
Form = GetForm(...)
and
Form.OpenForm(...) code strings.
See also: Opening managed forms in Minimizing the number of server calls.
2. For parameterizable forms, all parameters must be provided in the form's parameter set. By this, all the form's parametrization options are described in the parameter set in a declarative way.
Specify the parameters in the code that opens the form (OpenForm).
3. It is not recommended to adopt other practices to parameterize forms. For example, once a form is opened, don't address form's methods and properties.
Incorrect:
MyForm = Form.OpenForm("CommonForm.SystemGuide");
MyForm.Items.GroupStep.CurrentPage = MyForm.Items.GroupStep.Pages.Salutation;
Correct:
OpenForm("CommonForm.SystemGuide", New Structure("OpeningMode", "Salutation"));
4. To get a return value from the form, don't address the form's elements and attributes directly. Incorrect:
QuestionForm = GetForm("CommonForm.QuestionForm");
QuestionForm.DoModal();
If QuestionForm.DoNotShowReminder Then
// …
Instead, embed a notification handler that is called on form close. Correct:
Notification = New NotifyDescription("DoNotShowReminderEnd", ThisObject);
OpenForm("CommonForm.QuestionForm",,,,, Notification, FormWindowOpeningMode.LockWholeInterface);
...
&AtClient
Procedure DoNotShowReminderEnd(DoNotShowReminder, Parameters) Export
If DoNotShowReminder = Undefined Then
Return;
EndIf;
If DoNotShowReminder Then
// …
EndProcedure
In this case, the return value is generated in the code of the form's module with the Close method.
See also: Restrictions on the use of export procedures and functions
- Do not embed code that opens another form into the OnOpen event handler. This might lead to an unexpected form display order. Instead, embed a shot-time idle handler or let the user to open other forms interactively.
- It is not recommended to employ solutions where a single handler programmatically opens and closes the form. Form opening and form closing must be staggered. For example, embed code that closes the from into an idle handler.
- If you develop a form specifically for external users, ensure that this form will never open in the local user's sessions. To do so, in the Users or UsersClient common module, embed the Cancel parameter to code block that creates the form for external users (IsExternalUserSession):
&AtServer
Procedure OnCreateAtServer(Cancel, StandardProcessing)
If Not UsersClientServer.IsExternalUserSession() Then
Cancel = True;
Return;
EndIf;
…
EndProcedure
6. Make sure the following forms are available to users in the All Functions menu, even if they are hidden from the command interface.
-
Main list form
-
Main form of data processor
-
Main form of report