/ Microsoft / Calculate totals of PO using X++ in D365FO

Calculate totals of PO using X++ in D365FO

Learn, share and spread knowledge
Calculate totals of PO using X++ in D365FO

It is often difficult to calculate the totals of PO using X++ in D365FO. The form of totals in Purchase order shows different totals of PO, but it is difficult for developers to get them using X++ code. For this purpose, I am writing this article to give you the code to calculate the totals of PO using X++.

What is purchase order?

According to Microsoft documentation, a purchase order (PO) is a document that represents an agreement with a vendor to buy goods or services. The document also helps keep track of product receipts that are made toward the order and, later, the accounting of vendor invoices that the vendor bills toward the order.

What is totals of PO?

According to Microsoft documentation, you can review the totals of PO using the following steps:

  • 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++

Calculate totals of PO using X++ in D365FO
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, I hope it will work on AX 2012 as well.

So, in this way you can calculate totals of PO using X++ in D365FO. Moreover, if this helps you, please Like, Comment and Share to help other people.

If you found any ambiguity or a better solution, please feel free to ask.

See also: Get total debit and credit against voucher in x++

Website: Click here

Blog: Click here

YouTube: Click here

GitHub: Click here

Facebook: Click here

You just can’t beat the person who won’t give up. – Babe Ruth

0 POST COMMENT

Send Us A Message Here

Your email address will not be published. Required fields are marked *

NevoiTech Blog

A blog by Moeen Ahmed SultanNevoiTech logo

To hire freelancer or get personal training

of

Call/WhatsApp: +92 321 458 9595

Email: info@nevoitech.com