Modifying the posting procedure

Let us modify the document posting procedure.

  1. In Designer, open the GoodsReceipt document editor window and click the Posting tab.
  2. Add the CostOfMaterials register to the list of registers affected by the document (fig. 11.3).


    Fig. 11.3. Creating records of the GoodsReceipt document in the CostOfMaterials register
  3. Click Register records wizard.
  4. Confirm that you want to replace the previously generated posting procedure.

    By doing this you do not lose any data because you have not changed the previously generated procedure and the new one will add records to both registers.

    In the Register Records Wizard window you can see that all of the fields related to the BalanceOfMaterials register contain data that you specified earlier, when you set up record generation for this register in section Creating register records of a document.
  5. Click the Add  button above the Registers list and add the CostOfMaterials register (fig. 11.4).


    Fig. 11.4. Register records wizard

    The default register record type is Receipt (the  icon is displayed next to the register name).
  6. In the Tabular Section list, select Materials.

    It is the tabular section of the GoodsReceipt document.

    Once you select the tabular section, its attributes are added to the Document attributes list, which already contains the document header attributes.
  7. 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.

    Let us specify the mapping for the Cost register field.
  8. In the Field column, click the Cost field, and then, in the Document attributes list, double-click the CurRowMaterials.Total attribute (fig. 11.5).


    Fig. 11.5. Register records wizard
  9. Click OK.

    The wizard generates a procedure in the GoodsReceipt document module and opens the module. You can see that the new handler procedure includes the generation of records in two registers (listing 11.1).

    Listing 11.1. Records of the GoodsReceipt document

    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 CostOfMaterials Receipt
        RegisterRecords.CostOfMaterials.Write = True;
        For Each CurRowMaterials In Materials Do
            Record = RegisterRecords.CostOfMaterials.Add();
            Record.RecordType = AccumulationRecordType.Receipt;
            Record.Period = Date;
            Record.Material = CurRowMaterials.Material;
            Record.Cost = CurRowMaterials.Total;
        EndDo;
     
        //}}__REGISTER_REGISTERRECORDS_WIZARD
    EndProcedure
    You can see that the script fragment that describes the record generation for the CostOfMaterials register is similar to the script fragment that describes the record generation for the BalanceOfMaterials register.

    But having two loops that iterate through the Materials tabular section is not optimal, you can use a single loop for this.
  10. Combine the two loops into one and delete the comments generated by the wizard.

    Then your procedure should look as shown in listing 11.2.

    Listing 11.2. Records of the GoodsReceipt document

    Procedure Posting(Cancel, Mode)
     	
        RegisterRecords.BalanceOfMaterials.Write = True;
        RegisterRecords.CostOfMaterials.Write = True;
     	
        For Each CurRowMaterials In Materials Do
        // register BalanceOfMaterials Receipt
     
            Record = RegisterRecords.BalanceOfMaterials.Add();
            Record.RecordType = AccumulationRecordType.Receipt;
            Record.Period = Date;
            Record.Material = CurRowMaterials.Material;
            Record.Warehouse = Warehouse;
            Record.Quantity = CurRowMaterials.Quantity;
     
        // register CostOfMaterials Receipt
            Record = RegisterRecords.CostOfMaterials.Add();
            Record.RecordType = AccumulationRecordType.Receipt;
            Record.Period = Date;
            Record.Material = CurRowMaterials.Material;
            Record.Cost = CurRowMaterials.Total;
        EndDo;
    	 
    EndProcedure
Next page: Adding the command that opens register records
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.