How to Calculate purchase order total value using X++ in Dynamics 365 FO?
What is a Purchase Order?
A Purchase Order is a document that represents a request to a vendor to supply goods or services at a specific price and delivery date. The purchase order includes details such as the quantity, unit price, and delivery date of the items or services requested, as well as the vendor's information and the buyer's information.
A purchase order is typically created in the procurement and sourcing module in Dynamics 365 Finance and Operations, and it can be generated automatically from a requisition or manually entered by a user. Once the purchase order is approved and sent to the vendor, it serves as a legally binding agreement between the buyer and the seller.
The purchase order also serves as a basis for tracking the status of the order and receiving the items or services in the receiving and warehousing module. It can also be used for invoice matching and for tracking vendor performance metrics.
Why this article?
It is often difficult to calculate the totals of PO using X++ in D365FO. The form of totals in the 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 Total?
In Dynamics 365 Finance and Operations, the Purchase Order Total refers to the total cost of the items or services requested in a purchase order. This includes the price of the items or services, any applicable taxes or fees, and any additional charges such as shipping or handling fees.
The Purchase Order Total is calculated automatically in Dynamics 365 Finance and Operations based on the details entered in the purchase order. It can be viewed on the purchase order form and can also be used in various financial and accounting processes, such as budgeting, cost accounting, and financial reporting.
Having an accurate Purchase Order Total is important for effective budget management and financial control, as it enables buyers to track and manage their purchasing activities more effectively and provides greater transparency into the costs associated with their procurement processes.
In Dynamics 365 FO, you can review the totals of PO using the following steps:
1. Under Module > Click on Procurement and Sourcing Module.2. Under purchase orders > Click on All purchase order menu.
3. You can see all the purchase orders created previously, select one purchase order.
You can see the Total under the Purchase Order tab on the action bar.
4. Click the menu Total, and a dialog box shows totals for the whole order.
Calculate the purchase order total value using X++
For this,
1. Create a runnable class (job) named as CalculatePurchaseOrderTotals.
2. Copy the below code and paste it into the newly created class.
internal final class CalculatePurchaseOrderTotals { public static void main(Args _args) { //Calculate totals per Purchase order PurchTotals purchTotals; PurchTable purchTable = PurchTable::find('00000041'); //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)); } }
3. Change the Purchase order id according to your system’s purchase order data. Here we selected 00000041 as the purchase order id.
4. Successfully build and run the job.
5. You can see the purchase order total value in the info log as shown below,
If this article is useful to you, please try to share it with your friends, if you have any doubts about this article please comment in the comment box.
Published on:
Learn moreRelated posts
Sales Collaboration: How Sales Teams Work in Dynamics 365 CE
A Sales Team in Microsoft Dynamics 365 Sales represents a group of users who collaborate to manage and close sales opportunities efficiently. ...
Environment Variables vs Configuration Tables vs Hardcoding in Dynamics 365 Customer Engagement (CE)
In Dynamics 365 Customer Engagement (CE), managing configuration values effectively is key to building scalable and maintainable solutions. En...
Ticket sales management with Dynamics CRM in the Sports Industry
Mohona Dutta By Mohona Dutta | Reading time 5 mins So, how do you prospect? Pulling names out of lists on your laptop? Repeatedly calling...
How to create an impactful fan experience in sports with Dynamics CRM?
Mohona Dutta By Mohona Dutta | Reading time 5 mins For a salesperson, every day is game day. Sports organizations are always looking to i...
Updating JavaScript code in Dynamics CRM Made Easy for Developers
Hema Shamala By Hema Shamala | Reading time 5 mins Why do we need JavaScript in D365 CRM? It allows us to implement custom logic by using...
How To Use Advanced Find in Dynamics CRM 365
Nikhil Rajendran By Nikhil Rajendran | Reading time 5 mins One of the most commonly used features in Dynamics 365 is Advanced Find. A d...
Simplifying License Management for Dynamics 365 Finance and Operations: Improved User License Validation
Microsoft is updating the timeline for in-app notifications and per-user license validation to give customers more time to prepare. To enable ...
Simplifying License Management for Dynamics 365 Finance and Operations: Improved User License Validation
In-product notifications and user subscription license (USL) validation has been amended for customers in FY25 Q4, FY26 Q1 renewals. Microsoft...
Security Model of Dynamics CRM
Business Unit – It is a way to group business activities.When an organization is created, a Root Business Unit is created by default. Thi...






