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 :
Microsoft Dynamics AX (Archived)

AX2012 X++ partial posting of purch lines

(0) ShareShare
ReportReport
Posted on by

I want to post the invoice of selected lines of purch order(PO) through code. need help in the code. can anyone help me with coding ?

*This post is locked for comments

I have the same question (0)
  • Bilal Issa Profile Picture
    4,370 on at

    Hi,

    as simple method you can use the following:

     PurchTable purchTable;

       PurchLine  purchLine;

       PurchFormLetter PurchFormLetter;

      ;

       PurchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);

       ttsBegin;

       purchTable = purchTable::find('PurchId');    

       while select forupdate purchLine

       where

       purchLine.purchId == purchTable.PurchId

       {

           purchLine.PurchReceivedNow = 1 ;//  Qty you want to invoice ;

           purchLine.modifiedField(fieldnum(purchLine,PurchReceivedNow));

           purchLine.update();

       }

       PurchFormLetter.update(purchTable,'InvoiceNumber',today(),PurchUpdate::ReceiveNow);

       ttsCommit;

    Regards,

    Bilal

  • Community Member Profile Picture
    on at

    when I run the above code , it shows error "The result of the invoice matching process  for invoice Test1303 is unknown. View the invoice in the Posting invoice form or perform invoice matching on the invoice and then post." ??

    is this code does post partial lines. for e.g. I have 10 lines and I want to post 5 out of it for invoice.

  • Mariano Gracia Profile Picture
    on at

    It's more complex than modifying PurchReceivedNow quantity and trying to post invoice. What inventory dimensions will you use in your invoice?, will inventory dimensions be informed in the purch order lines?, will you post partial quantities in the purch order lines?. Have you tried to look at inventory receptions functionallity?, it allows you to post a partial reception, and then, you can post invoice from packing slip.

  • Suggested answer
    Amir Nazim Profile Picture
    5,994 on at

    check if this helps you ? this is for sales invoice but with minor modifications it should work for purchase side also.

    axlearning.blogspot.com/.../partial-sales-order-through-code-in.html

  • Srinath Sundaresan Profile Picture
    510 on at
  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at

    Hi All,

    X++ Code to Create Purchase Order and Post the Invoice.

    Following code will create the Purchase order from code and post the invoice as well by making use of "PurchFormLetter" class.

    static void TheaxaptaCreatePOInvoice(Args _args)

    {

    NumberSeq numberSeq;

    Purchtable Purchtable;

    PurchLine PurchLine;

    PurchFormLetter purchFormLetter;

    ;

    ttsbegin;

    numberSeq = NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequence,true);

    // Initialize Purchase order values

    Purchtable.initValue();

    Purchtable.PurchId = numberSeq.num();

    Purchtable.OrderAccount = '3000';

    Purchtable.initFromVendTable();

    if (!Purchtable.validateWrite())

    {

    throw Exception::Error;

    }

    Purchtable.insert();

    // Initialize Purchase Line items

    PurchLine.PurchId = Purchtable.PurchId;

    PurchLine.ItemId = 'B-R14';

    PurchLine.createLine(true, true, true, true, true, false);

    ttscommit;

    purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);

    purchFormLetter.update(purchtable, // Purchase record Buffer

    "Inv_"+purchTable.PurchId, // Invoice Number

    systemdateget()); // Transaction date

    if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice)

    {

    info(strfmt("Posted invoiced journal for purchase order %1",purchTable.PurchId));

    }

    }

    You can Change the document status to packingSlip , if you want to post packing slip by using the same code.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans