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).


    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).


    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  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).


    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).


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).


    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.

Comments
0
Add comment