X++ code to create PO by taking vendor from dialog (AX Classes)
Code :-
class BAS_PurchaseOrderCreation extends RunBase
{
DialogField fieldvendaccount;
VendTable vendtable;
VendAccount vendaccount;
public Object Dialog()
{
//To get the fields on dialog
Dialog dialog;
dialog = super();
//set the caption for dialog field
dialog.caption("Select Vendor Account");
//add field to dailog window
fieldvendaccount = dialog.addField(extendedTypeStr(VendAccount),"VendorAccount");
return dialog;
}
public boolean getfromDialog()
{
vendaccount = fieldvendaccount.value();
return super();
}
public void run()
{
PurchTable purchTable;
PurchLine purchLine;
vendtable = VendTable::find(vendaccount);
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(016\2012);
axPurchTable.parmPurchStatus(PurchStatus::Backorder);
axPurchTable.parmInventSiteId('CENTRAL');
axPurchTable.parmInventLocationId('AUSTIN');
axPurchTable.doSave();
//Create PurchLine for item 1000
purchLine.initFromPurchTable(purchTable);
axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId("0001");
axPurchLine.parmPurchQty(10);
axPurchLine.parmPurchPrice(100);
axPurchLine.doSave();
purchLine.clear();
purchLine.initFromPurchTable(purchTable);
axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId("0002");
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("PO_%1", purchTable.PurchId));
////Posting PO Invoice
//purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
//purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));
}
public static void main(Args _args)
{
BAS_PurchaseOrderCreation purchaseorder = new BAS_PurchaseOrderCreation();
if(purchaseorder.prompt())
{
purchaseorder.run();
}
}
}
Comments
Post a Comment