Skip to main content
Answer

Unable to update key field OperationCD on Production Order Operation

  • January 17, 2023
  • 4 replies
  • 145 views

Freeman Helmuth
Semi-Pro I
Forum|alt.badge.img

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

Hi @Freeman Helmuth -

Did you see the comment on your StackOverflow thread from Jan 24? It looks like the poster updated his example to try to answer your question…

This is repasted from that thread. In your original code, you are trying to set operationCD using SetValueExt, which is probably not correct. I would try to do it the way the StackOverflow thread suggests instead….unfortunately I haven’t used these features before so I don’t really have a test environment to produce a working example.

        PXResultset<AMProdOper> prodOperResultSet = prodDetailMaint.ProdOperRecords.Select();

foreach(EWPMBatchProcessStep batchStep in this.BatchProcessStep.Select()) {
AMProdOper prodOper = FindAMOper(prodOperResultSet, amProdItem, batchStep.AMProdOperID);

if(prodOper.OperationCD != batchStep.BatchProcessStepCD) {
prodOper.OperationCD = batchStep.BatchProcessStepCD;
}
prodDetailMaint.ProdOperRecords.Update(prodOper);

 

4 replies

Freeman Helmuth
Semi-Pro I
Forum|alt.badge.img

Here’s another variation that we’ve tried now. This shows the problem the best: A new row is getting inserted into cache instead of the existing one being updated.

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • March 15, 2023

Hi @Freeman Helmuth  were you able to find a solution? Thank you!


Freeman Helmuth
Semi-Pro I
Forum|alt.badge.img

No. And it’s still an issue that we’re facing.

Have not tried it on the latest update but doubtful that’ll make any difference.


Forum|alt.badge.img+5
  • Semi-Pro III
  • Answer
  • March 19, 2023

Hi @Freeman Helmuth -

Did you see the comment on your StackOverflow thread from Jan 24? It looks like the poster updated his example to try to answer your question…

This is repasted from that thread. In your original code, you are trying to set operationCD using SetValueExt, which is probably not correct. I would try to do it the way the StackOverflow thread suggests instead….unfortunately I haven’t used these features before so I don’t really have a test environment to produce a working example.

        PXResultset<AMProdOper> prodOperResultSet = prodDetailMaint.ProdOperRecords.Select();

foreach(EWPMBatchProcessStep batchStep in this.BatchProcessStep.Select()) {
AMProdOper prodOper = FindAMOper(prodOperResultSet, amProdItem, batchStep.AMProdOperID);

if(prodOper.OperationCD != batchStep.BatchProcessStepCD) {
prodOper.OperationCD = batchStep.BatchProcessStepCD;
}
prodDetailMaint.ProdOperRecords.Update(prodOper);