Item number cannot be changed when item transactions have been generated. Delete line and re-create it with the new item number. in AX (D365O) - Create Sales Order via X++
Hi,
Error:
Item number cannot be changed when item transactions have been generated. Delete line and re-create it with the new item number. in AX (D365O).
Solution:
While Creating Sales Line i have received above error and resolved by adding salesline.clear();
inventDim.clear();
Create Sales Order via X++
//creating sales order header
//getting sales order id from number sequence
numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
numberSeq.used();
salesTable.SalesId = numberSeq.num();
salesTable.initValue();
salesTable.CustAccount = strCustAccount;
salesTable.InventSiteId=int2Str(2);
salesTable.InventLocationId =int2Str(24);
salesTable.initFromCustTable();
//validate
if (!salesTable.validateWrite())
{
throw Exception::Error;
}
salesTable.insert();
ttsCommit;
ttsBegin;
InventDim inventDim;
salesline.clear();
inventDim.clear();
salesLine.SalesId = salesTable.SalesId;
salesLine.CustomerLineNum = str2Int(strCustomerLineNum);
salesLine.ItemId =strItemId;
salesLine.SalesPrice = str2Num(strSalesPrice);
salesLine.SalesQty= str2Num(strSalesQty);
salesLine.SalesUnit =strSalesUnit;
inventDim.InventSiteId=int2Str(2);
inventDim.InventLocationId=int2Str(24);
salesLine.InventDimId=InventDim::findDim(inventDim).inventDimId ;
salesLine.createLine(true,true,true,true,true,true);
ttsCommit;
}
Error: Sales Price is not updating in Sales Line i.e. Unit Price
Solution: try below piece of code it works
ttsBegin;
InventDim inventDim;
salesline.clear();
inventDim.clear();
salesLine.initValue();
salesLine.SalesId = salesTable.SalesId;
salesLine.initFromSalesTable(salesTable);
salesLine.CustomerLineNum = str2Int(strCustomerLineNum);
salesLine.ItemId =strItemId;
salesLine.itemIdChanged();
salesLine.SalesQty= str2Num(strSalesQty);
salesLine.SalesUnit =strSalesUnit;
inventDim.InventSiteId=int2Str(2);
inventDim.InventLocationId=int2Str(24);
salesLine.InventDimId=InventDim::findDim(inventDim).inventDimId ;
real unitPrice=str2Num(strSalesPrice);
salesLine.SalesPrice = unitPrice;
salesLine.LineAmount = salesLine.calcLineAmount();
salesLine.createLine(true,false,false,true);
ttsCommit;
Error:
Item number cannot be changed when item transactions have been generated. Delete line and re-create it with the new item number. in AX (D365O).
Solution:
While Creating Sales Line i have received above error and resolved by adding salesline.clear();
inventDim.clear();
Create Sales Order via X++
static void createSalesTable(CustAccount _custAccount) {ttsBegin;
//creating sales order header
//getting sales order id from number sequence
numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
numberSeq.used();
salesTable.SalesId = numberSeq.num();
salesTable.initValue();
salesTable.CustAccount = strCustAccount;
salesTable.InventSiteId=int2Str(2);
salesTable.InventLocationId =int2Str(24);
salesTable.initFromCustTable();
//validate
if (!salesTable.validateWrite())
{
throw Exception::Error;
}
salesTable.insert();
ttsCommit;
ttsBegin;
InventDim inventDim;
salesline.clear();
inventDim.clear();
salesLine.SalesId = salesTable.SalesId;
salesLine.CustomerLineNum = str2Int(strCustomerLineNum);
salesLine.ItemId =strItemId;
salesLine.SalesPrice = str2Num(strSalesPrice);
salesLine.SalesQty= str2Num(strSalesQty);
salesLine.SalesUnit =strSalesUnit;
inventDim.InventSiteId=int2Str(2);
inventDim.InventLocationId=int2Str(24);
salesLine.InventDimId=InventDim::findDim(inventDim).inventDimId ;
salesLine.createLine(true,true,true,true,true,true);
ttsCommit;
}
Error: Sales Price is not updating in Sales Line i.e. Unit Price
Solution: try below piece of code it works
ttsBegin;
InventDim inventDim;
salesline.clear();
inventDim.clear();
salesLine.initValue();
salesLine.SalesId = salesTable.SalesId;
salesLine.initFromSalesTable(salesTable);
salesLine.CustomerLineNum = str2Int(strCustomerLineNum);
salesLine.ItemId =strItemId;
salesLine.itemIdChanged();
salesLine.SalesQty= str2Num(strSalesQty);
salesLine.SalesUnit =strSalesUnit;
inventDim.InventSiteId=int2Str(2);
inventDim.InventLocationId=int2Str(24);
salesLine.InventDimId=InventDim::findDim(inventDim).inventDimId ;
real unitPrice=str2Num(strSalesPrice);
salesLine.SalesPrice = unitPrice;
salesLine.LineAmount = salesLine.calcLineAmount();
salesLine.createLine(true,false,false,true);
ttsCommit;
Yruemoef-ge Keith Hunt https://wakelet.com/wake/6xr4xR6zNJsVmZTuYAuij
ReplyDeletepecmamava