Skip to main content

Create Purchase order or Sales order and invoice through X++


static void CreatePOAndInvoice(Args _args)

{
     PurchTable      purchTable;
     PurchLine       purchLine;
     VendTable       vendTable = VendTable::find("1000");
     AxPurchTable    axPurchTable;
     AxPurchLine     axPurchLine;
     PurchFormLetter purchFormLetter;
     ;

    //Create Purchase order
     purchTable.initFromVendTable(vendTable);

     axPurchTable = axPurchTable::newPurchTable(purchTable);
     axPurchTable.parmPurchaseType(PurchaseType::Purch);
     axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
    // axPurchTable.parmAccountingDate(systemDateGet());
     axPurchTable.parmDeliveryDate(01\06\2012);
     axPurchTable.parmPurchStatus(PurchStatus::Backorder);
     axPurchTable.doSave();

    //Create PurchLine for item 1000
     purchLine.initFromPurchTable(purchTable);

    axPurchLine = AxPurchLine::newPurchLine(purchLine);
     axpurchLine.parmItemId("Test29");
     axpurchLine.parmInventDimId('00000063_069');
     axPurchLine.parmPurchQty(10);
     axPurchLine.parmPurchPrice(100);
     axPurchLine.doSave();

    //Posting PO Confirmation,I guess its mandatory
    //You cannot do invoice without doing PO confirm
    purchTable = axPurchTable.purchTable();
     purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
     purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));

    //Posting PO Invoice
     purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
     purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));

}

Comments

  1. thanks for post,
    I am new ax technology and i am to learn ax2012 and this blog help to me increase my knowledge..

    ReplyDelete
  2. Hi Amir,
    Good to see you here!!
    You can go through the blog to help enhance your technical skills in AX.
    If anyone have any doubts, can also post that.

    ReplyDelete
  3. Hi Vishal
    Can u please give me you mail Id and Contact Number.

    ReplyDelete
  4. http://shrishailtechnologies.wordpress.com/2012/04/27/ax-2012-x-code-to-create-and-post-purchase-order-invoice/

    ReplyDelete
  5. This code will not invoice because it needs document date for posting, only pending invoice will be created

    ReplyDelete

Post a Comment