Thursday, 15 February 2018

Create purchase order using x++ code in Ax 2012

Purchase order creation in Ax 2012 using x++

Declaration

    NumberSeq   numberSeq;
    PurchTable  purchTable;
    PurchLine   purchLine;

Getting Number sequence

    numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
    numberSeq.used();
    purchTable.PurchId = numberSeq.num();


Find the vendor account

purchTable.initFromVendTable(VendTable::find('US-101'));

Validation 

    if (!purchTable.validateWrite())
    {
        throw Exception::Error;
    }

Adding line item and details

    purchLine.PurchId   = purchTable.PurchId;
    purchLine.ItemId    = '1000';

Create line details and checking validation  

purchLine.createLine(true, true, true, true, true, true);


Code

Creating open purchase order 

static void PurchaseOrderCreation(Args _args)
{
    NumberSeq   numberSeq;
    PurchTable  purchTable;
    PurchLine   purchLine;
    ;
    
    ttsBegin;
    // geting number sequence
    numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
    numberSeq.used();
    // Asign purch id
    purchTable.PurchId = numberSeq.num();
    // calling table initvalue method
    purchTable.initValue();
    // find the vendor account 
    purchTable.initFromVendTable(VendTable::find('US-101'));
    // validation
    if (!purchTable.validateWrite())
    {
        throw Exception::Error;
    }
    // insert data
    purchTable.insert();
    purchLine.PurchId   = purchTable.PurchId;
    purchLine.ItemId    = '1000';
    // Purch line creation
    purchLine.createLine(true, true, true, true, true, true);
    ttsCommit;
    info(strFmt("Purchase order '%1' has been created",purchTable.PurchId));
    
}

2 comments:

  1. How to data insert WITHHOLDING TAX table ON A PURCHASE ORDER – X++

    ReplyDelete
  2. How to data insert WITHHOLDING TAX table ON A PURCHASE ORDER – X++..Please send me technical coding

    ReplyDelete

Step-by-Step Guide to Restore a SQL BACPAC File - Microsoft dynamics D365 Fin & Ops

 Restore steps for bacpac file in to SQL server - Microsoft dynamics D365 Fin & Ops. Log in to LCS and navigate to the asset library. On...