Friday, 4 December 2015

How to Create Purchase Order Through Code in X++

static void PurchOrderCreate(Args _args)
{
    NumberSeq numberSeq;
    PurchTable purchTable;
    PurchLine purchLine;
    ttsBegin;
    numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
    numberSeq.used();
    purchTable.PurchId = numberSeq.num();
    purchTable.initValue();
    purchTable.initFromVendTable(VendTable::find('8009'));
    if (!purchTable.validateWrite())
    {
        throw Exception::Error;
    }
    purchTable.insert();
    purchLine.PurchId = purchTable.PurchId;
    purchLine.ItemId = 'A0001';
    purchLine.createLine(true, true, true, true, true, true);
    ttsCommit;
    info(strFmt("Purchase order '%1' has been created",purchTable.PurchId));
}

1 comment: