Wednesday, June 22, 2022

D365FO - Calculate totals of PO using X++

Select Totals. If you don’t see the Totals action, select the Purchase Order tab on the action bar.

  • This dialog box shows totals for the whole order.
  • The Selection field allows you to change the basis of how totals are calculated. For example, you could choose Product receipt quantity to show totals that relate to the amount of the product(s) that have been received, or Ordered quantity to show the amount of product that was ordered.
  • Select OK.

Calculate total amount of PO using X++



Total amount of Purchase order in Microsoft Dynamics 365 for Finance and Operations
  • Create a runnable class (job) named as CalculateTotalsOfPurchaseOrder
  • Copy the below code and paste in the newly created class
  • Change the Purchase order id according to your system’s data
  • Execute the job
class CalculateTotalsOfPurchaseOrder
{
    public static void main(Args _args)
    {
        //Calculate totals per Purchase order
        PurchTotals purchTotals;
        PurchTable  purchTable  = PurchTable::find('PO.000018'); //Change the Purchase Order Id as per your system's data
        AmountCur   totalAmount;
        purchTotals = PurchTotals::newPurchTable(purchTable);
        purchTotals.calc();
        totalAmount = purchTotals.purchTotalAmount();
        info(strFmt("Purchase order: %1 - Total value: %2", purchTable.PurchId, totalAmount));
    }
}

You will see the total amount of the specified PO on the screen. Please note that I have tested this code in D365FO 

Ref

No comments:

Post a Comment