Hi Guys,
I am working with 23R2.
I have encountered an error where my custom action, in an extension of the MoveEntry graph, gives me the error:
Cannot insert duplicate key row in object 'dbo.PressGlueLogHeader' with unique index 'PressGlueLogHeader_NoteID'. The duplicate key value is (b74bff6a-8e54-ef11-af2d-b81ea4b981b6, 2).
The statement has been terminated.
Below is my MoveEntry Extension:
public class MoveEntryQCExt : PXGraphExtension<MoveEntry>
{
public static bool IsActive() => true;
#region Actions
public PXAction<AMBatch> StartQCChecks;
[PXButton]
[PXUIField(DisplayName = "Start QC Checks", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
protected virtual IEnumerable startQCChecks(PXAdapter adapter)
{
var moveEntry = PXGraph.CreateInstance<MoveEntry>();
if(moveEntry == null)
{
return adapter.Get();
}
var qcEntry = PXGraph.CreateInstance<GCQualityControlEntry>();
var move = Base.batch.Current;
var record = qcEntry.QCCheck.Insert();
record.NoteID = Guid.NewGuid();
record.BatchNbr = move.BatNbr;
record.DocType = move.DocType;
record.Date = move.TranDate;
qcEntry.QCCheck.Update(record);
var details = qcEntry.Details.Insert();
var tran = Base.transactions.Current;
foreach (AMMTran lines in Base.transactions.Select())
{
details.AMProdOrdID = tran.ProdOrdID;
details.TranDate = tran.TranDate;
qcEntry.Details.Update(details);
}
moveEntry.Actions.PressSave();
qcEntry.Actions.PressSave();
PXRedirectHelper.TryRedirect(qcEntry, PXRedirectHelper.WindowMode.New);
return adapter.Get();
}
public PXAction<AMBatch> RecordPressGlueLogs;
[PXButton]
[PXUIField(DisplayName = "Record Press Glue Logs", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
protected virtual IEnumerable recordPressGlueLogs(PXAdapter adapter)
{
var moveEntry = PXGraph.CreateInstance<MoveEntry>();
if(moveEntry == null)
{
return adapter.Get();
}
var logEntry = PXGraph.CreateInstance<GCPressGlueLogEntry>();
var move = Base.batch.Current;
var header = logEntry.Header.Insert();
header.NoteID = Guid.NewGuid();
header.BatchNbr = move.BatNbr;
header.DocType = move.DocType;
header.Date = move.TranDate;
logEntry.Header.Update(header);
logEntry.Actions.PressSave();
moveEntry.Actions.PressSave();
PXRedirectHelper.TryRedirect(logEntry, PXRedirectHelper.WindowMode.New);
return adapter.Get();
}
#endregion
#region Events
protected virtual void _(Events.RowSelected<AMBatch> e, PXRowSelected b)
{
AMBatch row = e.Row;
if (row == null) return;
if (row.Status == "R")
{
StartQCChecks.SetEnabled(true);
RecordPressGlueLogs.SetEnabled(true);
}
}
#endregion
}
Both actions cause the same issue, the issue persists with and without the header/record.NoteID = Guid.NewGuid(); line.
Is there something I should do differently when extending the MoveEntry graph?
Does anyone know/have a clue about why this could be happening?
Any suggestions would be greatly appreciated!