Hi,
X++ Code to Create Purchase Order and Post the Invoice in AX D365
Below Job creates the Purchase order from code and post the invoice by use of PurchFormLetter class.
static void Dev_CreatePO_and_Invoice(Args _args)
{
NumberSeq numberSeq;
Purchtable Purchtable;
PurchLine PurchLine;
PurchFormLetter purchFormLetter;
;
ttsbegin;
//numberSeq = //NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequenc//e,true);
// Initialize Purchase order values
Purchtable.initValue();
Purchtable.PurchId = NumberSeq::newGetNum(PurchParameters::numRefPurchId()).num();//numberSeq.num();
Purchtable.OrderAccount = '3000';
Purchtable.initFromVendTable();
if (!Purchtable.validateWrite())
{
throw Exception::Error;
}
Purchtable.insert();
// Initialize Purchase Line items
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId = 'B-R14';
PurchLine.createLine(true, true, true, true, true, false);
ttscommit;
purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchtable, // Purchase record Buffer
"Inv_"+purchTable.PurchId, // Invoice Number
systemdateget()); // Transaction date
if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice)
{
info(strfmt("Posted invoiced journal for purchase order %1",purchTable.PurchId));
}
}
X++ Code to Create Purchase Order and Post the Invoice in AX D365
Below Job creates the Purchase order from code and post the invoice by use of PurchFormLetter class.
static void Dev_CreatePO_and_Invoice(Args _args)
{
NumberSeq numberSeq;
Purchtable Purchtable;
PurchLine PurchLine;
PurchFormLetter purchFormLetter;
;
ttsbegin;
//numberSeq = //NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequenc//e,true);
// Initialize Purchase order values
Purchtable.initValue();
Purchtable.PurchId = NumberSeq::newGetNum(PurchParameters::numRefPurchId()).num();//numberSeq.num();
Purchtable.OrderAccount = '3000';
Purchtable.initFromVendTable();
if (!Purchtable.validateWrite())
{
throw Exception::Error;
}
Purchtable.insert();
// Initialize Purchase Line items
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId = 'B-R14';
PurchLine.createLine(true, true, true, true, true, false);
ttscommit;
purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchtable, // Purchase record Buffer
"Inv_"+purchTable.PurchId, // Invoice Number
systemdateget()); // Transaction date
if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice)
{
info(strfmt("Posted invoiced journal for purchase order %1",purchTable.PurchId));
}
}
citiOic-na Jeff Krogman https://wakelet.com/wake/hyNb9Fu-uAYvlJFMr2NiO
ReplyDeletebinanewma