0
votes

I am trying to generate a production order and insert one detail line. When creating the detail line, everything is going well until I try to call the Persist or Update methods. When I do that, the line I'm trying to insert is duplicated and I receive the following error: Another process has added the 'AMProdMatl' record. Your changes will be lost.

Here is a brief example of my code:

        AMProdMatl fabric = new AMProdMatl();
        fabric = graphDetail.ProdMatlRecords.Insert(fabric);
        //Set values
        AMProdMatlExt fabricExt = fabric.GetExtension<AMProdMatlExt>();
        //Set values
        fabric = graphDetail.ProdMatlRecords.Update(fabric);
        graphDetail.Persist();

Why is it trying to insert a second duplicate record and how can that be fixed?

1
AMProdMatl has a parent which relies on the line counter logic. Check the LineID value used on the insert to make sure it is not a key already existing. If so make sure that current AMProdOper record is set in cache so the correct next line counter is used. - Brendan

1 Answers

0
votes

This usually occurs when trying to insert a record that has a different value in a key field. If between Insert and Update you are changing a key field than for the platform that is a new record. When Inserting a new record using the Insert method ensure that you have set the key fields for that DAC otherwise on update this will be treated as separate record causing the effect of inserting two records instead of one.