Monday 24 December 2018

Job to create pending vendor invoice through X++ code in D365FO

A vendor invoice from a purchase order is an invoice that is produced when products or services are received according to a purchase order that was placed with a vendor. The vendor invoice contains a header, and one or more lines for items or services. A vendor invoice completes the cycle from purchase order to product receipt to vendor invoice. In this blog I will discuss how we can create pending vendor invoice through X++ code in Dynamic 365 finance and operations. So lets begin.

Please follow series of screenshots of source code with explanation:

Source code explanation: (1.1)
  • Initialization of table buffers.
  • Get purchase order table. 
  • Get purchase order lines.
  • Get vendor table.























Source code explanation: (1.2)

  • Insert data in VendInvoiceInfoTable table.
  • This table contains the vendor invoices for one or more purchase orders.
  • Assignment of values.

















Source code explanation: (1.3)
  • Insert data in VendInvoiceInfoSubTable table.
  • This table contains the associations between the vendor invoices and the purchase orders.
  • Assignment of values.










Source code explanation: (1.4)
  • Insert data in VendInvoiceInfoLine table.
  • This table contains vendor invoice lines for a specific purchase order.
  • Assignment of values.














Source code explanation: (1.5)
  • Insert data in VendInvoiceInfoSubLine table.
  • This table contains associations between the vendor invoice lines and the posted vendor packing slips.
  • Assignment of values.













That is all you need to do for creating pending vendor invoice through X++ code.

5 comments:

  1. Hi,
    Thanks for your Post.
    I am getting the below error when i try to post the Pending vendor invoice .

    Number: Item: Invoice quantity is greater than the quantity matched to product receipts

    Please help on this

    ReplyDelete
  2. Hi,

    Error says the quantity you received and the quantity you invoiced is not same. Invoice Quantity should be same as receipt. Please check your product receipt quantity and pass that quantity to your invoice that will resolve your issue.

    ReplyDelete
  3. Hi I was not able to match the price. it keep on saying failed only could you please help me with this? Price matching is failing

    ReplyDelete
  4. Hi,

    Thanks for the post. I reused your code to create it myself. But it still can be improved with simple methods.
    For example
    1.VendInvoiceSubTable::createFromVendInvoiceInfoTable(vendInvoiceInfoTable, true) instead of just inserting all the fields apart.
    2. vendInvoiceInfoLine.initFromPurchLine(vendPackingslipTrans.purchLine()); much easier than all these fields apart.
    ...

    But still a big thank you!

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete

How to fix Error: "Common Language Runtime detected an invalid program" in D365FO

Recently, we upgraded our environment, which resulted in one of our customizations, previously working flawlessly, throwing the "Common...