Hello:
Trying to programmatically update the OperationCD field on a production order operation, but getting an error that the “Another process has added the Note Record”.
This operation works just fine in the UI, but not via code
I found another user with the same issue on StackOverflow, but he did not post his solution:
acumatica - Another Process has added a "Note" Record(ProdDetail) in 22R1 - Stack Overflow
Upon investigating the source code, it looks like Acumatica is inserting a new record into the cache instead of updating the existing record, but I can’t figure out why.
Here’s the code:
public class LaborEntryReorderExt : PXGraphExtension<LaborEntry>
{
public static bool IsActive()
{
return true;
}
public PXAction<AMBatch> RunReorder;
[PXButton]
[PXUIField(DisplayName = "Run Reorder")]
protected void runReorder()
{
List<AMMTran> ammTransactionsToRelease = new List<AMMTran>();
foreach (AMMTran ammTran in Base.transactions.Select())
{
ammTransactionsToRelease.Add(ammTran);
//MaxOperationID = Math.Max(MaxOperationID, ammt.OperationID.Value);
//OrderType = ammt.OrderType;
//OrderNbr = ammt.ProdOrdID;
PXTrace.WriteInformation("Resequencing: '" + ammTran.OrderType + "' " + ammTran.ProdOrdID);
}
//setup a local graph to manipulate the production detail record
ProdDetail prodDetailGraph = PXGraph.CreateInstance<ProdDetail>();
//get the current production detail record from the cache
AMProdItem prodOrderRecord = PXSelect<AMProdItem,
Where<AMProdItem.orderType, Equal<Required<AMProdItem.orderType>>,
And<AMProdItem.prodOrdID, Equal<Required<AMProdItem.prodOrdID>>>>>
.Select(prodDetailGraph, ammTransactionsToRelease[0].OrderType, ammTransactionsToRelease[0].ProdOrdID);
//set the graph variable to use the production detail record from the cache
prodDetailGraph.ProdItemRecords.Current = prodOrderRecord;
//set hold
if ((bool)prodOrderRecord.Hold != true)
{
//put the production order on hold. Have to do this in order to renumber the operations
prodDetailGraph.ProdItemRecords.Cache.SetValueExt<AMProdItem.hold>(prodOrderRecord, true);
prodOrderRecord.Hold = true;
}
foreach (AMProdOper amProdOper in prodDetailGraph.ProdOperRecords.Select())
{
//hardcoded ids for testing
if (amProdOper.OperationID == 5)
{
PXTrace.WriteInformation("Reordering " + ammTransactionsToRelease[0].OperationID);
prodDetailGraph.ProdOperRecords.Cache.SetValueExt<AMProdOper.operationCD>(amProdOper, "0200");
amProdOper.OperationCD = "0200";
prodDetailGraph.ProdOperRecords.Update(amProdOper);
}
}
prodOrderRecord = prodDetailGraph.ProdItemRecords.Update(prodOrderRecord);
prodDetailGraph.Save.PressButton();
}
}
Best answer by rosenjon
View original