1C:Enterprise 8.3. Practical Developer’s Guide. Lesson 27 (2:10). Form development techniques. Using parameterized commands

Using parameterized commands

You can use parameterized commands in object forms to pass some parameter (for example, a value of a reference attribute) to a command handler. This parameter will be available for further use, for example, you can open a report form using the parameter.

We will explain this on the example of a command that opens a Balance of materials report for a warehouse specified in a document. The report is opened from the Services document form, and the Warehouse document attribute value is passed to the report. When the report is opened, a filter by the Warehouse parameter is added to the report settings.

In Designer mode

First, let us create a parameterized command for the Materials report configuration object.

  1. Open the configuration object editor of the Materials report.
  2. On the Commands tab, click Add Lesson 27 (2:10). Form development techniques / Using parameterized commands / In Designer mode and create a command named BalanceByWarehouse.
  3. In the property palette that is opened, set Command parameter type to CatalogRef.Warehouses.
  4. Set the Group property to Form command bar.Important (fig. 27.37).

    Lesson 27 (2:10). Form development techniques / Using parameterized commands / In Designer mode
    Fig. 27.37. Creating a parameterized command

    So you have created a command with a parameter of CatalogRef.Warehouses type. This command is automatically added to the list of available parameterized commands of each form that includes an attribute of that type.
  5. In the command module that is opened, fill the handler as shown in listing 27.6.

    Listing 27.6. Parameterized command event handler

    Procedure CommandProcessing(CommandParameter, CommandExecuteParameters)
        FormParameters = New Structure("Filter,PurposeUseKey,GenerateOnOpen",
            New Structure("Warehouse", CommandParameter), "BalanceByWarehouse", True);
        OpenForm("Report.Materials.Form", FormParameters, CommandExecuteParameters.Source,
            True, CommandExecuteParameters.Window);
    Let us examine this script.

    The CommandProcessing() procedure receives a CommandParameter that contains a value of the CatalogRef.Warehouses type. Next the structure of form parameters (FormParameters) is created. It includes the following parameters: Filter, PurposeUseKey, and GenerateOnOpen.

    A structure that contains the Warehouse item with the value passed in the command parameter (CommandParameter) is assigned to the Filter parameter. The PurposeUseKey parameter, which defines the form purpose, is set to BalanceByWarehouse. The GenerateOnOpen parameter is set to True, which defines that the report is generated immediately after opening.

    Next the form parameter structure is passed to the global OpenForm() method and the form specified in the first parameter of the method is opened with the Warehouse parameter. Since the fourth method parameter Uniqueness is set to True, every time the form is opened it is a new report form and the report is generated based on the warehouse filter passed in the command parameter.

    Now let us add the command to the document form.

    As we mentioned earlier, the forms of the GoodsReceipt and Services documents include the BalanceByWarehouse command because they include the Warehouse attribute of the CatalogRef.Warehouses type.
  6. Open the Services document form.
  7. On the Commands tab, click the Global commands tab.

    Here you can see the list of global parameterized commands available in the form.
  8. In the Parametrizable group, expand the Object item and drag the Report.Materials.Command.BalanceByWarehouse(Object.Warehouse) command to the command bar of the form controls.

    The part enclosed in parentheses (Object.Warehouse) is the value of the Warehouse attribute passed to the command (fig. 27.38).

    Lesson 27 (2:10). Form development techniques / Using parameterized commands / In Designer mode
    Fig. 27.38. Adding a parameterized command to a form

    Note that you have not created a report form nor have you added a filter by the Warehouse form parameter to the report settings. It is done automatically when the BalanceByWarehouse event handler is executed.

In 1C:Enterprise mode

Let us test the changes.

  1. Start 1C:Enterprise in the debug mode.
  2. Open the Services document #CI0000001.
  3. Click Balance by warehouse.

    This opens the Materials report. Its form is generated automatically. The report is generated with a filter by Main warehouse once the form is opened (because this warehouse is specified in the document form, fig. 27.39).

    Lesson 27 (2:10). Form development techniques / Using parameterized commands / In 1C:Enterprise mode
    Fig. 27.39. Materials report with a filter by warehouse specified in the document
  4. Close the report.
  5. In the document form, change Warehouse to Retail.
  6. If this document contains any material rows, delete them.

    This is required because earlier in this lesson you added a fill check for material rows and once you change anything in the document, the platform cannot save it and display the report because of the unfilled Property set field.
  7. Click Balance by warehouse.

    This opens the Materials report with a filter by Retail warehouse (in this case the report is empty because you have not entered any materials stored in this warehouse).

    So you have implemented a user-friendly feature: opening a report that displays material balances for a warehouse directly from the document form with a filter by warehouse specified in the document.

Leave a Reply

Your email address will not be published. Required fields are marked *

1C:Enterprise Developer's Community