web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Create Purchase order invoice without product receipt through X++ code

(0) ShareShare
ReportReport
Posted on by 758

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.

I have the same question (0)
  • Suggested answer
    Satish Panwar Profile Picture
    14,671 Moderator on at

    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.

  • Rhushikesh R Profile Picture
    758 on at

    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?

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    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
    }

  • Rhushikesh R Profile Picture
    758 on at

    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.

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Rhushikesh,

    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();
    }

  • Rhushikesh R Profile Picture
    758 on at

    Thanks Sergie. But May I know how to store records in purchtableset and purchlineset?

  • Sergei Minozhenko Profile Picture
    23,093 on at

    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);

  • Rhushikesh R Profile Picture
    758 on at

    But Sergie, do I need to create the record in vendInvoiceInfoTable first before writing above code?

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Rhushikesh,

    No, it should be created automatically (when you call prePromptInit).

  • Rhushikesh R Profile Picture
    758 on at

    Hi Sergie,

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans