PurchPrice in PurchaseOrder

Hi!!

I am trying to insert purchprice from customize table into purchline table. but no record inside the table after i run the code.
Why this happen. Below is the line i used:

purchLine.purchprice = tblPOLine.unitPrice;

Can someone help me?

Can u share the total code…what all you have wriiten in order to achieve the given scenario.

Hi Misha,

There is no special logic in updating this field in PurchLine table. As long as insert() or update() is called, value in this field should get updated.

BTW if you are creating purchase order lines from X++ code directly, use ‘createLine()’ method.

Hye Vishal and Harish,

Below is the code i have created.

public void InsertPO(TablePOHeader tblPOHeader)
{
NumberSeq numberSeq;
PurchTable purchTable;
VendTable tblvend;
LedgerDimensionAccount ledgerDimAcc;
VendGroup tblvendgroup;
Currency tblcurrency;
DimensionAttributeValueCombination tblLedgerDimension;
PurchLine tblline;
DimensionStorage clsdimensionstorage;
InventDimId invntdimid;
InventTable tblinvent;
InventDim tblInventDim;
TablePOLine tblPOLine;
PurchFormLetter purchFormLetter;
PurchLine purchLine;
AccountNum strAccountNo;
ItemId strItemId;
PurchPrice realprice;
UnitOfMeasureSymbol UOM;
InventTableModule tblInventTableModule;
;

ttsBegin;
select purchTable where purchTable.PurchId == tblPOHeader.POID;
if(!purchTable)
{
purchTable.initValue();
purchTable.PurchId = tblPOHeader.POID;
purchTable.CurrencyCode = tblPOHeader.Currency;
strAccountNo = tblPOHeader.VendorCode;
tblvend = VendTable::find(strAccountNo);
purchTable.OrderAccount = strAccountNo;
purchTable.initFromVendTable(VendTable::find(tblvend.AccountNum));
if(!purchTable.validateWrite())
{
throw Exception::Error;
}
purchTable.insert();

ttsBegin;
while select forUpdate tblPOLine
where tblPOLine.POID == tblPOHeader.POID
&& tblPOLine.Process == LKP_Process::New
&& tblPOLine.ProcessedDate == systemDateGet()
{
select tblInventDim where tblInventDim.InventSiteId == tblPOLine.Site;
if(tblInventDim)
{
purchLine.clear();
purchLine.purchId = purchTable.PurchId;
strItemId = tblPOLine.ItemId;
realprice = tblPOLine.UnitPrice;
UOM = tblPOLine.UOM;
purchLine.LineNumber = tblPOLine.LineNum;
purchLine.ItemId = strItemId;
purchLine.PurchPrice = realprice;
purchLine.PurchQty = tblPOLine.QtyOrdered;
purchLine.PurchReceivedNow = tblPOLine.QtyDelivered;
purchLine.LineAmount = tblPOLine.Amount;
purchLine.DeliveryDate = tblPOLine.DeliveryDate;
tblInventDim.InventSiteId = tblPOLine.Site;
purchLine.InventDimId = InventDim::findOrCreate(tblInventDim).inventDimId;
tblInventDim.InventLocationId = tblPOLine.Location;
tblInventDim.inventBatchId = tblPOLine.Batch;
purchLine.InventDimId = tblInventDim.inventDimId;
purchLine.createLine(true, true, true, true, true, true); //-<< i have used purchLine.createLine as u said.
}
tblPOLine.Process = LKP_Process::Done;
tblPOLine.update();
}
ttsCommit;

purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update( purchTable, tblPOHeader.POID , systemDateGet(), PurchUpdate::All, AccountOrder::None, NoYes::No, NoYes::Yes);
purchFormLetter.run();
}
ttsCommit;
info(strFmt(“Purchase order ‘%1’ has been created”,purchTable.PurchId));
}

Hi Misha,

You did not say version of AX. It is crucial because ‘CreateLine’ method varies depending on the AX version

Firstly - looking through the code, I notice you are setting ‘realprice’ value to ‘PurchLine table > PurchPrice field’. I hope value is correctly populated to this variable.

Secondly - I notice you are sending ‘true’ parameters to ‘CreateLine’ method. Check the parameters in this method and ensure that this value does not overwrite pricing details. You can do this by setting debugging point on the line with ‘CreateLine’ method. Check the PurchLine table buffer before this line and after this line gets executed.

Hope this makes sense.