The Infolog

A blog of Dynamics AX development tips and tricks

Skip to: Content | Sidebar | Footer

Getting a pending invoice totals

27 November, 2015 (14:37) | Dynamics AX | By: Howard Webb

I needed to create a report which gathered the totals for a pending purchase invoice. Investigating the totals form You can see that it uses the class PurchTotals to calculate the total values. However this uses a PurchParmUpdate record, and at this point a permanent record in the table is not created yet. To get the PurchTotals class to work correctly we would need to create the temp PurchParmUpdate record, calculate the totals and then delete the temporary records. Below is the code to do this. Note that we have to declare the child class of PurchFormLetter to call the correct method:


PurchTable               purchTable;
PurchTotals              purchTotals;
real                     discAmount;
VendInvoiceInfoTable     vendInvoiceInfoTable;
VendInvoice              vendInvoice;
PurchParmUpdate          purchParmUpdate;
PurchFormLetter_Invoice  purchFormLetter;
ParmId                   parmId;
;

select firstOnly vendInvoiceInfoTable
    where vendInvoiceInfoTable.recID == 5637146096;

purchFormLetter = new PurchFormLetter_Invoice();

purchFormLetter.init();

purchFormLetter.parmCallerTable(vendInvoiceInfoTable);

purchFormLetter.initNewFromSaved(vendInvoiceInfoTable);

purchFormLetter.chooseLines();

parmId = purchFormLetter.parmId();

purchParmUpdate = purchFormLetter.purchParmUpdate();

purchTotals = PurchTotals::newParmTable( vendInvoiceInfoTable, purchParmUpdate.SpecQty, AccountOrder::None, parmId, '', vendInvoiceInfoTable.Ordering);

purchTotals.calc();

discAmount = purchTotals.purchTotalAmount();

purchFormLetter.deleteParmUpdate();