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?