1C:Enterprise 8.3. Practical Developer’s Guide. Lesson 6 (0:50). Accumulation registers. Adding an accumulation register

Adding an accumulation register

Now that you know the purpose of accumulation registers, let us discuss how to use them in our example.

We are mostly concerned with the quantity and type of materials available in the warehouses. To accumulate this information, let us create the BalanceOfMaterials register.

In Designer mode

Let us create the accumulation register.

  1. Open your configuration in Designer.
  2. In the configuration object tree, click the Accumulation registers branch and then click the Add Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode button in the configuration window command bar.

    This opens the configuration object editor window.
  3. On the Main tab, in the Name field, type BalanceOfMaterials.
  4. In the Extended list presentation field, type Register records for Balance of materials.

    It will be displayed in the title of the register records list window.
  5. Click Next.

    This opens the Subsystems tab. The logic of your configuration suggests that the register should be available in the Accounting, Inventory, and Services sections.
  6. Select the Accounting, Inventory, and Services check boxes (fig. 6.3).

    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode
    Fig. 6.3. Specifying subsystems where a register is available
  7. Click the Data tab.

    Here you can define the register structure.
  8. Click the Dimensions branch and then click the Add Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode button in the command bar of the window (fig. 6.4) to add the following register dimensions:
    • Material. Type: CatalogRef.MaterialsAndServices
    • Warehouse. Type: CatalogRef.Warehouses
    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode
    Fig. 6.4. Creating register dimensions
  9. Click the Resources branch and click the Add Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode button in the command bar of the window (fig. 6.5) to create the following resource:
    • Quantity. Length: 15, precision: 3
    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode
    Fig. 6.5. Creating register resources

Once you are done with these steps, the BalanceOfMaterials register should look as shown in fig. 6.6.

Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode
Fig. 6.6. BalanceOfMaterials register

At this point, if you attempt to start 1C:Enterprise in the debug mode, you get the error message: "AccumulationRegister.BalanceOfMaterials: None of the documents is a recorder for the register." This message confirms the fact that the accumulation register purpose is accumulating data provided by documents.

So let us set up generation of register records in the BalanceOfMaterials accumulation register during the posting of the two documents that you created: GoodsReceipt and Services.

In 1C:Enterprise mode

Let us test the changes that you made.

  1. Start 1C:Enterprise in the debug mode.

    You can see that the Balance of materials command that opens the register list is added to the Inventory, Services, and Accounting subsystems. It is located after other list opening commands and before the Create and Reports menus (if these menus are available, fig. 6.12).

    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In 1C:Enterprise mode
    Fig. 6.12. List of the BalanceOfMaterials accumulation register

    Now let us track the connection between document posting and data accumulation in the register.
  2. In the Accounting section, run the Goods receipts command.
  3. Open the first Goods receipt and click Post and close, then do the same for the second Goods receipt.

    This reposts the documents. You can also repost documents without opening them. To repost a document, select it in the list (you can select multiple documents by clicking them while holding down Ctrl), click More in the command bar of the list form, and click Post (fig. 6.13).

    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In 1C:Enterprise mode
    Fig. 6.13. Posting a document
  4. Run the Balance of materials command.

    This opens the accumulation register list (fig. 6.14).

    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In 1C:Enterprise mode
    Fig. 6.14. List of the BalanceOfMaterials accumulation register

    You can see that when you post goods receipts, respective records are added to the Balance of materials accumulation register. Note that five records are added: three records from posting the first document (this number matches the number of rows in its tabular section) and two records from posting the second document.

    All register fields are filled with the document data exactly as specified in the posting handler of the GoodsReceipt document. The Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In 1C:Enterprise mode icon to the left of each record indicates that the register record type is Receipt. As you can see, the title of the register record list form matches the one that you specified in the Extended list presentation property for this register.

Creating register records of a document

A register record of a document is a record generated in a register when a document is posted. It reflects the changes introduced by that document.

  1. Open the configuration object editor for the GoodsReceipt document.
  2. Click the Posting tab, expand the Accumulation registers list, and select the BalanceOfMaterials check box (fig. 6.7).

    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode / Creating register records of a document
    Fig. 6.7. Creating register records of the GoodsReceipt document in the BalanceOfMaterials register

    Note that once you select the check box, the Register records wizard button becomes available.

  3. Click the Register records wizard button.

    The wizard is straightforward. The Registers list displays the registers where the document can create records. In this case, the only register available is BalanceOfMaterials.

    The Document attributes list contains the data used to generate register records, that is, the attributes of the GoodsReceipt document.

    The table with Field and Expression columns stores the formulas used to calculate register dimension and resource values when a register record is generated (fig. 6.8).

    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode / Creating register records of a document
    Fig. 6.8. Register records wizard

    Note that by default the wizard prompts you to create a receipt register record for the BalanceOfMaterials register (Register Record Type is set to Receipt, and the Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode / Creating register records of a document icon is displayed next to the register name). This is fine with us since the document is GoodsReceipt and is intended to record received materials.
  4. In the Tabular Section list, select Materials.

    It is the only tabular section in the document. Note that its attributes are added to the Document attributes list.
  5. Click Fill Expressions.

    In the bottom pane the mapping between the register fields (dimensions and resources) and the expressions for calculating their values is generated (fig. 6.9).

    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode / Creating register records of a document
    Fig. 6.9. Selecting a document tabular section and filling expressions for calculating register records

    As you can see, the register records wizard defined the mapping appropriately: it took material from the document tabular section for material, warehouse specified in the document header for warehouse, and quantity from the document tabular section for quantity.
  6. Click OK.

    The wizard generates a procedure in the GoodsReceipt document module and opens the module (listing 6.1).

    Listing 6.1. Posting() procedure

    Procedure Posting(Cancel, Mode)
        //{{__REGISTER_REGISTERRECORDS_WIZARD
        // This fragment was built by the wizard.
        // Warning! All manually made changes will be lost next time you use the wizard.
    
        // register BalanceOfMaterials Receipt
        RegisterRecords.BalanceOfMaterials.Write = True;
        For Each CurRowMaterials In Materials Do
            Record = RegisterRecords.BalanceOfMaterials.Add();
            Record.RecordType = AccumulationRecordType.Receipt;
            Record.Period = Date;
            Record.Material = CurRowMaterials.Material;
            Record.Warehouse = Warehouse;
            Record.Quantity = CurRowMaterials.Quantity;
        EndDo;
    
        //}}__REGISTER_REGISTERRECORDS_WIZARD
    EndProcedure

It is the Posting event handler for the GoodsReceipt document configuration object.

The Posting event is one of the most important document events. This event occurs when a document is posted. The main purpose of this event handler is generating register records for the document. The data operations in the handler procedure affect the accounting records. So this is the place where developers implement custom algorithms that are executed during document posting.

Now lets us study the handler procedure script.

The DocumentObject 1C:Enterprise script object has the RegisterRecords property. It returns the RegisterRecordsCollection object, which contains a collection of register record sets that this document can use to generate register records.

You can address a specific record set of this collection by writing the name of the register that stores the record set after a dot (.). For example, RegisterRecords.BalanceOfMaterials.

Next, after a dot you can use register record sets methods, for example, RegisterRecords.BalanceOfMaterials.Add(). The Add() method adds a record to the record set.

The first line of the procedure assigns the True value to the Write property of the register record set. So it explicitly specifies that once the posting is completed the platform writes this record set to the database.

The handler includes the loop For Each … In … Do. This loop is intended to iterate through the document tabular section rows.

In the loop the document tabular section is called by its name (Materials). The CurRowMaterials variable contains an object storing the data of the current document tabular section row. This variable is created at the beginning of the loop and changes with each iteration.

In the first line of the loop body the Add() method adds a record to the record set that the document creates in the register. To be exact, it creates an AccumulationRegisterRecord object and saves it to the RegisterRecord variable.

Using this object, you can call the fields of the record by writing the field name after the variable, separated by a dot (for example, RegisterRecord.Quantity).

Note that Record.Material and Record.Warehouse are register dimensions, Record.Quantity is a register resource, and Record.RecordType and Record.Period are standard register attributes that are generated automatically.

In order to assign values to the fields of the new register record, tabular section fields are addressed by writing their names after the CurRowMaterials variable and a dot (for example, CurRowMaterials.Material).

Note that Warehouse is an attribute of the document header, while Date is a standard document attribute that is generated automatically. Note that only the values of the document tabular section are changed within the loop (CurRowMaterials.Material and CurRowMaterials.Quantity). Other fields are not changed because they belong to the entire document and do not depend on the document tabular section row.

AccumulationRecordType.Receipt is the value of the system enumeration that defines the type of the accumulation register record type as Receipt.

So the required values are assigned to all the fields of the new record. After iterating through all document rows (when the loop is completed), the record set (RegisterRecords.BalanceOfMaterials) contains the number of records that is equal to the number of rows in the tabular section of the posted document.

If you open the configuration object editor for the BalanceOfMaterials accumulation register and click the Recorders tab, you will see that the GoodsReceipt check box is now selected because you set up generation of register records for the BalanceOfMaterials register in the document module (fig. 6.10).

Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode / Creating register records of a document
Fig. 6.10. Recorders of the BalanceOfMaterials register

Finally, let us edit the command interface to add the link for viewing the accumulation register records to the Accounting, Services, and Items subsystems.

Commands that open registers are added to the section command panels but, unlike commands that open catalogs or documents, they are hidden by default.

  1. In the configuration object tree, right-click the Subsystems branch and then click All subsystems.
  2. In the All Subsystems window, in the Subsystems list, click Inventory.

    The Command interface list displays all the commands of the selected subsystem.
  3. In the Navigation panel.Normal group, enable visibility for the Balance of materials command and drag it to the Navigation panel.See also group (fig. 6.11).

    Lesson 6 (0:50). Accumulation registers / Adding an accumulation register / In Designer mode / Creating register records of a document
    Fig. 6.11. Specifying subsystem command interface settings

    Indeed, the commands that open accumulation registers are used less frequently so it is better to move them to the bottom of the section command list.
  4. Perform the same procedure for the Services and Accounting subsystems: in the Navigation panel.Normal group, enable visibility for the Balance of materials command and drag it to the Navigation panel.See also group.

Leave a Reply

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

1C:Enterprise Developer's Community