Solved

Unable to update key field OperationCD on Production Order Operation

  • 17 January 2023
  • 4 replies
  • 80 views

Userlevel 4
Badge

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();

}
}

 

icon

Best answer by rosenjon 19 March 2023, 01:39

View original

4 replies

Userlevel 4
Badge

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.

 

Userlevel 7
Badge

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

Userlevel 4
Badge

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.

Userlevel 6
Badge +5

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);

 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved