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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

How to do partial purchase order invoice using x++

(0) ShareShare
ReportReport
Posted on by 25

Good Morning,

Hope you all are fine.

I have an xml file in that i have Invoicenum and from lines i have Qty,Itemid,Sales price.

There is already Purchase order line created with this itemid.

Now i want to import this file to staging table which works fine but after then i need to post invoice with the Qty,Salesprice.

I am not able to find code in internet to post partial invoice. I found some code to post partial invoice after received but in that case they are gettinng data from vendpackingslipjour.

In my case i have only Qty,Salesprice and purchline and purchtable.

It would be helpful if i get some code to post invoice through X++

Regards,

Have a nice day.

I have the same question (0)
  • ggjhj Profile Picture
    25 on at

    Dear experts please provide any help on this

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi,

    Please check this post. It has some sample code to post purchase order invoice.

  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi,

    There was also a similar thread before community.dynamics.com/.../create-purchase-order-invoice-without-product-receipt-through-x-code

  • ggjhj Profile Picture
    25 on at

    Hi Gunjan,

    Thank you for reply.

    I am searching for partial invoice code.It would be helpful if i  get partial posting where i can specify qty and unitprice.

    Regards,

    Have a nice day.

  • ggjhj Profile Picture
    25 on at

    Hi Sergei,

    Hope you are fine.

    Is this code correct or if i am missing anything.

    public static void postPOInvoiceInvoiceId      _invoiceNo)
        {
            PurchFormLetter_Invoice     purchFormLetter;
            PurchTable                  purchTable,purchTableUpd;
            PurchLine                   purchLine, purchLineFind, purchLineUpd;
            PurchParmUpdate             purchParmUpdate;
    
    
            VendInvoiceInfoTable        vendInvoiceInfoTable,vendInvoiceInfoTableUpd;
    
            PurchId                     purchId;
            PackingSlipId               packingSlipId;
            SetIterator                 setIteratorPurchLine, setIteratorPurchLine1;
            ;
            Set purchTableSet = new Set(Types::String);
            Set purchLineSet  = new Set(Types::Int64);
            purchId = "Service -001";
            ttsBegin;
    
    
            purchTable = PurchTable::find(purchId);
    
            purchTableSet.add(purchTable.PurchId);
            while select purchLine
                where purchLine.PurchId == purchId
            {
                purchLineSet.add(purchLine.RecId);
            }
            //update Qty to be invoiced
            while select forupdate purchLine 
                where purchLine.PurchId == purchId
            {
                purchLine.reread(); //this line is required as Purchline table has Occ enabled property set to Yes
                purchLine.PurchReceivedNow = 6;
                purchLine.update();
                purchLineSet.add(purchLine.RecId);
            }
            //update Qty to be invoiced
            purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
    
            purchFormLetter.purchTable(purchTable);
            purchFormLetter.transDate(today());
            purchFormLetter.specQty(PurchUpdate::ReceiveNow);
            purchFormLetter.printFormLetter(NoYes::No);
            purchFormLetter.prePromptInit();
            purchParmUpdate = purchFormLetter.purchParmUpdate();
            purchFormLetter.initParameters(purchParmUpdate);
            purchFormLetter.purchParmUpdate(purchParmUpdate);
    
            vendInvoiceInfoTable = VendInvoiceInfoTable::findPurchId(purchTable.PurchId, purchFormLetter.parmId(), true);
            select forupdate vendInvoiceInfoTableUpd where vendInvoiceInfoTableUpd.RecId == vendInvoiceInfoTable.RecId;
            vendInvoiceInfoTableUpd.Num = _invoiceNo;
            vendInvoiceInfoTableUpd.update();
            setIteratorPurchLine = new SetIterator(purchLineSet);
            Info(strFmt("%1", vendInvoiceInfoTable.RecId));
      
            purchFormLetter.purchSelectLines(purchTableSet, purchLineSet, vendInvoiceInfoTable);
            if (purchFormLetter.validate())
            {
                purchFormLetter.reArrangeNow(false);
                purchFormLetter.run();
            }
            ttscommit;
            info("invoiced successfully");
        }

    But in that link i found some code to update '"vendInvoiceInfoLineUpd"

    pastedimage1611771835157v1.png

    Should i include this as well ?

    is there any code in standard application that does partial invoice in system.

    Because i am not sure if i miss something that might effect customer only.

    Its a kind request sergei if we have anything in standard application to post partial invoice.

    Regards,

    Have a nice day.

  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi ggjhj,

    The code itself should be correct and it's using quantity = "receive now" approach which requires setting value for PurchReceivedNow field in the original order line.  The approach will not work with parallel postings (several invoices for the same purchase order at the same time).

    The second part is not needed in this case and used with quantity = "All" approach.

    Also, there is another option now available using SalesVendorInvoiceInfoCreator to create draft data for invoice posting and invoice itself is posted in a separate queue via process automation framework. You can find examples in code by searching for cross-referencies for class SalesVendorInvoiceInfoCreator.

  • ggjhj Profile Picture
    25 on at

    Hi Sergei,

    I used this code

     PurchFormLetter purchFormLetter;
            PurchTable purchTable;
            purchTable = PurchTable::find('20051522');
            purchFormLetter = PurchFormLetter::construct(
                DocumentStatus::Invoice);
    
            purchFormLetter.update(
    purchTable,
    'nnnnntttt',
    DateTimeUtil::date(DateTimeUtil::utcNow()),
    PurchUpdate::PackingSlip,
    AccountOrder::None,
    NoYes::No,
    NoYes::Yes);

    But i am getting error invoice num must be filled in.

    Regards

  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi ggjhj,

    Seems that for AccountOrder::None you need to set up a number sequence in Procurement and Sourcing parameters (vendor invoice number) or try AccountOrder::Order.

  • ggjhj Profile Picture
    25 on at

    Hi Sergei,

    I tried  AccountOrder::Order facing same error.

    Can you please provide some code to post invoice for which product receipt has been done.

    PurchUpdate::Packingslip.

    In the above code in Set adding salesline records.

    How can we do it in this scenario.

    Please provide some light on this.

    Regards,

  • ggjhj Profile Picture
    25 on at

    Dear experts please provide some help on this

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans