I am trying to set a custom field I created in the INTranSplit table. I fetch the target record, set the custom field, update the view holding the records for the page, and perform a PressSave(). At some point during the save, the code sets the INTranSplit.TranDate to null and throws an exception.
Here is my code:
public PXAction<EMPWorkOrder> addSerialNbr;
[PXUIField(DisplayName = "Add Serial Number")]
protected void AddSerialNbr()
{
AvailableSNFilter serialNbrRow = AvailableSNs.Current;
if (serialNbrRow.AvailableSNs != null)
{
//Gets record from DAC created from a SQL View
GetAvailableSerialNumbers targetSN = (GetAvailableSerialNumbers)PXSelectorAttribute.Select<AvailableSNFilter.availableSNs>(AvailableSNs.Cache, serialNbrRow);
//Fetches the INTranSplit record
INTranSplit tran = PXSelect<INTranSplit, Where<INTranSplit.refNbr, Equal<Required<GetAvailableSerialNumbers.refNbr>>, And<INTranSplit.lotSerialNbr,
Equal<Required<GetAvailableSerialNumbers.lotSerialNbr>>, And<INTranSplit.inventoryID, Equal<Required<GetAvailableSerialNumbers.inventoryID>>
,And<INTranSplit.lotSerialNbr, NotEqual<Required<INTranSplit.lotSerialNbr>>>>>>>
.Select(this, targetSN.RefNbr, targetSN.LotSerialNbr, targetSN.InventoryID, string.Empty);//, targetSN.SplitLineNbr);
INTranSplitExt tranExt = PXCache<INTranSplit>.GetExtension<INTranSplitExt>(tran);
//Sets the custom field
tranExt.UsrWOID = CurrentDocument.Current.Id;
WorkOrderSerialNumbers.Update(tran);
serialNbrRow.AvailableSNs = string.Empty;
AvailableSNs.Update(serialNbrRow);
this.Actions.PressSave();
}
else
{
Document.Ask("AvailableSN Null", MessageButtons.OK);
}
}
The error I get is this:
Error #14: Updating 'IN Transaction Split' record raised at least one error. Please review the errors.
Error: 'Transaction Date' cannot be empty.
I stepped through the process and found that the TranDate is not null until after the code enters the PressSave() function.
Is there any way to solve this issue?