Monday, July 15, 2019

D365FO - Copy custom value from Accounts Payable Invoice Register (LedgerJournalTrans) to Invoice Approval (VendTrans)

When creating a accounts payable invoice register entry it will create a record in the table LedgerJournalTrans. Whenever you post this journal it will create a record for the journal in the VendTrans table.

If you go into the Invoice Approval form and click on "Find Vouchers" you will see that any custom fields you added to LedgerJournalTrans are available. However once one of these vouchers are loaded into the approval form you will find that the values are longer available. This is because it has converted your LedgerJournalTrans instance into its own VendTrans table instance.

In order to copy the values from LedgerJournalTrans to VendTrans you will need to extend the VendVoucher class which is shown below. It is good to note that in theory this method should be able to be applied to the CustVoucher (customer invoices) as it applies the same structure (CustVendTrans map) and using the common table method to pass VendTrans or CustTrans. 


[ExtensionOf(classStr(VendVoucher))]
final class APInvoiceModsVendVoucher_Extension
{
    

    /// <summary>
    /// COC of initCustVendTrans which sets the initial values of vendTrans from ledgerjournaltrans
    /// </summary>
    /// <param name = "_custVendTrans">VendTrans</param>
    /// <param name = "_ledgerPostingJournal">LedgerVoucher</param>
    /// <param name = "_useSubLedger">Use sub ledger default is false</param>
    protected void initCustVendTrans(
                                    CustVendTrans _custVendTrans,
                                    LedgerVoucher _ledgerPostingJournal,
                                    boolean _useSubLedger)
    {
        //execute the base functionality
        next initCustVendTrans(_custVendTrans, _ledgerPostingJournal, false);
        
        //get vendTrans table buffer form CustVendTrans map instance
        VendTrans vendTrans = _custVendTrans as VendTrans;
        
        //if the common instance is being initialized via the ledgerjournaltrans table we need to copy the custom field
        if (common && common.TableId == tableNum(LedgerJournalTrans))
        {
            LedgerJournalTrans ledgerJournalTrans = common;
            
            //copy internal invoice notes and the description from the ledgerjournal trans to the vendtrans
            vendTrans.CustomField = ledgerJournalTrans.CustomField;
            //this is not a custom field but the values do not get transfered
            vendTrans.Txt = ledgerJournalTrans.Txt;
        }
    }

}

No comments:

Post a Comment