Common module

Let us add a Common module configuration object.

  1. In the configuration object tree, expand the Common branch by clicking the  icon to the left of the branch name.
  2. Right-click the Common modules branch and click the Add  button in the command bar of the configuration window (fig. 4.24).

    Fig. 4.24. Creating a common module in the configuration object tree

    This opens the window where you can enter the module text and the module property palette.
  3. In the property palette, name the module DocumentProcessing, select the Client (managed application) check box, and clear the Server check box.

    It means that instances of this module will be compiled in the thin client context and in the web client context (fig. 4.25).

    Fig. 4.25. Common module propertiesAdd the following script to the module (listing 4.2).
  4. Listing 4.2. Procedure CalculateTotal()

    Procedure CalculateTotal (TabularSectionRow) Export
        TabularSectionRow.Total = TabularSectionRow.Quantity * TabularSectionRow.Price;
    Now let us examine this script. The TabularSectionRow variable that you defined in the OnChange event handler of the Quantity field is passed to the CalculateTotal() procedure. This variable stores data of the tabular section row of the Goods receipt document that is being edited.

    You can use this variable to access tabular section column data and calculate the total by multiplying the price and quantity.

    The Export keyword in the procedure title indicates that the procedure can be accessed from other applied solution modules.Change the handler script in the form module (listing 4.3).
  5. Listing 4.3. Procedure MaterialsQuantityOnChange()

    Procedure MaterialsQuantityOnChange(Item)
        TabularSectionRow = Items.Materials.CurrentData;
    You can see that the first line of the procedure remains unchanged. And in the second line instead of directly calculating the total the CalculateTotal() procedure from the DocumentProcessing common module is called. The current tabular section row is passed to the procedure as a parameter.Start 1C:Enterprise in the debug mode and ensure that nothing has changed from the user perspective.
  6. Finally, let us implement a similar handler for the Price field. Since you have already coded the required procedure in the form module, you might want to reuse it with a different control form. However, 1C Company configuration development standards do not permit that approach.

    Learn more! According to the 1C Company development standards, each event must have its own handler. If identical actions are to be performed in response to changes to different controls (for example, in response to clicking any of the several buttons), these should be handled as follows:
    • A dedicated procedure or function that performs the required actions is created.
    • For each control, a separate handler with a default name is created.
    • The procedure or function is called from each handler.
    This is why you will create the OnChange event handler for the MaterialsPrice field of the tabular section in the same manner as you have done it for the MaterialsQuantity field and repeat the call of the CalculateTotal() procedure from the common module.
  7. Add the OnChange event with the following script to the Price field (listing 4.4).

    Listing 4.4. Procedure MaterialsPriceOnChange()

    Procedure MaterialsPriceOnChange(Item)
        TabularSectionRow = Items.Materials.CurrentData;

Next page: In 1C:Enterpise mode
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.