Hi All,
When i Post Purchase order Invoice through code It through an error : Can not Insert Multiple records in VendInvoiceInfoTable
The Record Already Exist.
The code is given below:
NumberSeq numberSeq;
Purchtable Purchtable;
PurchLine PurchLine;
PurchFormLetter purchFormLetter;
;
ttsbegin;
numberSeq =NumberSeq::newGetNum(purchparameters::numRefPurchId(),true);
// Initialize Purchase order values
Purchtable.initValue();
Purchtable.PurchId = numberSeq.num();
Purchtable.OrderAccount =
‘OXI-016872’;
Purchtable.CurrencyCode =
‘INR’;
Purchtable.initFromVendTable();
if (!Purchtable.validateWrite())
{
throw Exception::Error;
}
Purchtable.insert();
// Initialize Purchase Line items
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId =
‘285’;
PurchLine.PurchQty =
2;
PurchLine.PurchPrice =
50;
PurchLine.createLine(
true, true, true, true, true, false);
PurchLine.clear();
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId =
‘1162’;
PurchLine.PurchQty =
1;
PurchLine.PurchPrice =
200;
PurchLine.createLine(
true, true, true, true, true, false);
ttscommit;
//PO confirmation
ttsBegin;
purchTable = PurchTable::find(purchTable.PurchId);
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable,
strFmt(“Inv_%1”, purchTable.PurchId));
ttsCommit;
//PO Product Receipt
ttsBegin;
purchFormLetter = purchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.update(purchtable,
// Purchase record Buffer
“PO_”+purchTable.PurchId, // Invoice Number
systemdateget()); // Transaction date
ttsCommit;
//PO Invoice
ttsBegin;
purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
//purchFormLetter.update(purchtable,“Inv_123”,systemdateget()); // Transaction date
//purchFormLetter.update(purchTable, strFmt(“PO_%1”, purchTable.PurchId));
purchFormLetter.update(purchtable,
// Purchase record Buffer
“INV-”+purchTable.PurchId, // Invoice Number
systemdateget()); // Transaction date
ttscommit;
if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice)
{
info(strfmt(“Posted invoiced journal for purchase order %1”,purchTable.PurchId));
}
AX Version 2012 R3
Kindly Help Me
Thanks in Advance.