Sunday, 27 April 2014

Purchase order creation and post through X++ in AX 2012

static void PurchOrderCreate(Args _args)
{
    PurchTable      purchTable;
    PurchLine       purchLine;
    VendTable       vendTable = VendTable::find("1001");
    AxPurchTable    axPurchTable;
    AxPurchLine     axPurchLine;
    InventDim           inventDim;
    PurchFormLetter purchFormLetter;

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

    axPurchTable = axPurchTable::newPurchTable(purchTable);
    axPurchTable.parmPurchaseType(PurchaseType::ReturnItem);
    axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
    axPurchTable.parmAccountingDate(systemDateGet());
    axPurchTable.parmDeliveryDate(09\09\2014);
    axPurchTable.parmPurchStatus(PurchStatus::Backorder);
    axPurchTable.doSave();

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

    axPurchLine = AxPurchLine::newPurchLine(purchLine);
    axpurchLine.parmItemId("0001");
    inventDim.InventLocationId = 'ANNA';
    inventDim.InventSiteId = 'EAST';
    inventdim = InventDim::findOrCreate(inventDim);
    axPurchLine.parmInventDimId(inventDim.inventDimId);
    axPurchLine.parmPurchQty(10);
    axPurchLine.parmPurchPrice(100);
    axPurchLine.doSave();

     //You cannot do invoice without doing PO confirm
    //purchTable = axPurchTable.purchTable();
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
    purchFormLetter.update(purchTable,purchTable.PurchId);
    info(strFmt('%1',purchTable.PurchId));

No comments:

Post a Comment