Friday, 30 November 2018

Job to get average unit cost of item through X++ code in D365

Recently I have encounter a scenario in which I want to get the average unit cost price of the item in D365FO. For that I have created a job to get the cost. Please follow below screenshots.

You can see the average unit cost price for item through this navigation Cost management -> Inventory accounting -> Released products -> Manage Costs (Tab) -> Costing (Section) -> Cost Object (Option).






















Source Code Explanation (1.1):
  • Initialize and declare objects.
  • Set Item Id = 'F-001' (in my case).
  • Get invent sum buffer through item id.
  • Check inventory dimension, in case of not found created one.

























Source Code Explanation (1.2):
  • Create an object of invent cost price cache class.
  • Get invent table buffer from invent sum.
  • Get from & to unit of measurement.
    • Construct secondary to invent unit converter buffer.
    • Get the convert value.
  • Get the OOTB cost price pieces method from cache class that will return average unit cost price of the item.










Result:



1 comment:

How to Get Customer Free Text Invoice "Totals" form field value with X++ in D365FO

Customer free text invoices are an essential aspect of financial management in D365FO. In this blog, I have compiled all the code needed to ...