Hello everyone,
In AR, “StageSalesTable” is my staging table. Additionally, I added the following fields to the inventory test: “Site,” “Warehouse,” “Batch number,” “Item number,” and “Product name.”
The record must be “posted” when I click the Process button, which initiates a batch job for a single record.
However, that record is in the “Ready to post” status, and the comment states that “Inventory dimension Batch number must be specified. Update has been canceled.”
For that record, I checked “All Sales Order” in AR. I observed that the “Batch number” field was not filled in with information from the “StageSalesTable.” However, the data for the remaining fields are visible.
I tried using the insert method on “StageSalesLine” at the table level. But still I am not finding any changes in the sales order.
Kindly help me with the changes in the below code to populate data in “sales order” from “StageSalesTable”.
Thanks in Advance.
Note: “this” in the below code refers to the table “StageSalesLine”.
switch(this.ItemId)
{
case (this.ItemId):
if(this.ItemId)
{
select * from salesLine where salesLine.ItemId == this.ItemId
join salesTable where salesTable.SalesId == salesLine.SalesId;
if(salesTable)
{
select * from inventDim where inventDim.inventDimId == salesLine.InventDimId;
if(inventDim)
{
inventDim.inventBatchId = this.inventBatchId;
inventDim.InventSiteId = this.SiteId;
inventDim.InventLocationId = this.InventLocationId;
}
}
}
}
First of all, let me repost your code to make it easier to read:
switch (this.ItemId)
{
case (this.ItemId):
if(this.ItemId)
{
select * from salesLine
where salesLine.ItemId == this.ItemId
join salesTable
where salesTable.SalesId == salesLine.SalesId;
if (salesTable)
{
select * from inventDim
where inventDim.inventDimId == salesLine.InventDimId;
if (inventDim)
{
inventDim.inventBatchId = this.inventBatchId;
inventDim.InventSiteId = this.SiteId;
inventDim.InventLocationId = this.InventLocationId;
}
}
}
}
The switch
statement makes no sense to me. What are you trying to achieve with that?
I see you just find the first order line for the given item. That doesn’t make a good sense to me either. There may be thousand lines with the same item; are you 100% sure that you don’t care which one you update?
There is no point checking whether the order line belongs to an order. Except of disastrous data corruption, there can’t be order lines for non-existing orders.
You set values if inventDim
buffer; but you’ve never saved the record nor you’ve update the order line. The correct approach is using findOrCreate()
to either find and existing ID for the given dimension combination, or to create a new one, and writing this ID to SalesLine
. For example:
InventDim inventDim = salesLine.inventDim();
inventDim.InventBatchId = this.InventBatchId;
inventDim.InventSiteId = this.SiteId;
inventDim.InventLocationId = this.InventLocationId;
salesLine.InventDimId = InventDim::findOrCreate(inventDim).InventDimId;
salesLine.update();
I did try the above code. But it’s showing the following error even after I try to use TTSBEGIN & TTSCOMMIT in the code.
“Cannot edit a record in Order lines (SalesLine). The operation cannot be completed, since the record was not selected for update. Remember TTSBEGIN/TTSCOMMIT as well as the FORUPDATE clause.”
If your code is wrapped in a transaction, then you’ve probably forgot to select the salesLine
buffer for update. For example:
select forUpdate salesLine
where...
I did used the following code, but still the Batch number isn’t populating in sales order
super();
if(this.ItemId)
{
ttsbegin;
select forupdate salesLine where salesLine.ItemId == this.ItemId;
if(salesLine.RecId)
{
inventDim = salesLine.inventDim();
inventDim.inventBatchId = this.inventBatchId;
inventDim.InventSiteId = this.SiteId;
inventDim.InventLocationId = this.InventLocationId;
salesLine.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
salesLine.update();
}
ttscommit;
}
How are you testing that?
I see you’re still selecting a random sales line, therefore the most likely explanation is that you’re checking the value in GUI but you’re looking at a different sales line than the one updated by your code.
Because the selection logic makes no sense, I strongly recommend fixing it before trying to test the update.
By the way, you’ve again posted your code in a wrong way, making it difficult to read. Put ``` on the lines just above and below your code snippet.