Notifications
Announcements
No record found.
Hi Everyone,
I need to create Purchase order invoice of multiple purchase line of a confirmed purchase order through X++ code without using product receipt.
Can anyone please help me with the code?
Thank you in advance.
Give link below a try:
shyamkannadasan.blogspot.com/.../code-to-create-purchase-order-and-post.html
All you need is PO number and use purchformletter.
Hi Satish,
I need to pass Purchase Line Number and Qty as well.
The code mentioned on link will invoice all purchase lines.
How can I achieve my requirement?
Hi Rhushikesh,
I used this snippet in AX2012.
purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice); purchFormLetter.purchTable(purchTable); purchFormLetter.transDate(InvoiceDate); purchFormLetter.printFormLetter(NoYes::No); purchFormLetter.prePromptInit(); purchParmUpdate = purchFormLetter.purchParmUpdate(); purchFormLetter.initParameters(purchParmUpdate); purchFormLetter.purchParmUpdate(purchParmUpdate); vendInvoiceInfoTable = VendInvoiceInfoTable::findPurchId(purchTable.PurchId, purchFormLetter.parmId(), true); purchFormLetter.purchSelectLines(purchTableSet, purchLineSet, vendInvoiceInfoTable);
PurchTableSet is set of PurchIds
PurchLineSet is set of PurchLine RecIds
To update quantities you can access vendInvoiceInfoLines after they are created
while select forupdate vendInvoiceInfoLine where vendInvoiceInfoLine.ParmId == vendInvoiceInfoTable.ParmId && vendInvoiceInfoLine.TableRefId == vendInvoiceInfoTable.TableRefId { //Update needed fields }
Hi Sergie,
I didn't find purchSelectLines method in D365. It gives me error. Also it would be great if you share full snippet of your code.
Thanks.
Yes, forgot to mention that purchFormLetter type is PurchFormLetter_Invoice.
And to run posting you will need to run the next code at the end.
if (purchFormLetter.validate()) { purchFormLetter.reArrangeNow(false); purchFormLetter.run(); }
Thanks Sergie. But May I know how to store records in purchtableset and purchlineset?
Hi,
Sure,
purchTableSet = new Set(Types::String); purchLineSet = new Set(Types::Int64); //Add as many lines as you need to the sets purchLineSet.add(YourPurchLine.RecId); purchTableSet.add(YourPurchLine.PurchId);
But Sergie, do I need to create the record in vendInvoiceInfoTable first before writing above code?
No, it should be created automatically (when you call prePromptInit).
I am getting below error while creating PO Invoice
No lines for posting or quantity = 0
Posting has been canceled.
Please check my code below,
public static void postPOInv(InvoiceId _invoiceNo, real _lineNum) { PurchFormLetter_Invoice purchFormLetter; PurchTable purchTable; PurchLine purchLine; PurchParmUpdate purchParmUpdate; VendInvoiceInfoTable vendInvoiceInfoTable; VendInvoiceInfoLine vendInvoiceInfoLine; VendInvoiceInfoSubTable vendInvoiceInfoSubTable; VendInvoiceInfoSubLine vendInvoiceInfoSubLine; PurchId purchId; PackingSlipId packingSlipId; ; purchId = "WCLPO-00102"; ttsBegin; purchTable = PurchTable::find(purchId); select purchLine where purchLine.PurchId == purchId && purchLine.LineNumber == _lineNum; Set purchTableSet = new Set(Types::String); Set purchLineSet = new Set(Types::Int64); purchTableSet.add(purchTable.PurchId); purchLineSet.add(purchLine.RecId); purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice); purchFormLetter.purchTable(purchTable); purchFormLetter.transDate(today()); purchFormLetter.printFormLetter(NoYes::No); purchFormLetter.prePromptInit(); purchParmUpdate = purchFormLetter.purchParmUpdate(); purchFormLetter.initParameters(purchParmUpdate); purchFormLetter.purchParmUpdate(purchParmUpdate); purchFormLetter.parmParmTableNum (_invoiceNo); vendInvoiceInfoTable = VendInvoiceInfoTable::findPurchId(purchTable.PurchId, purchFormLetter.parmId(), true); purchFormLetter.purchSelectLines(purchTableSet, purchLineSet, vendInvoiceInfoTable); if (purchFormLetter.validate()) { purchFormLetter.reArrangeNow(false); purchFormLetter.run(); } ttscommit; }
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 664 Most Valuable Professional
André Arnaud de Cal... 522 Super User 2025 Season 2
Sohaib Cheema 303 User Group Leader