0
votes

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?

1
Are you including INRegister in your graph? the PXDBDefault on INTranSplit.TranDate comes from INRegister.tranDate. - Brendan
I do have a view for INRegister directly. Is there anything I need to do with that? - EricP.
Possibly make sure it is populated with the related INRegister. Call viewname.select() depending on how your view is configured or at least make sure current is set in the view. - Brendan
Do I have to make the INRegister view directly related to the INTranSplit I am editing? If so I have an idea how to, but I think I will have to manually set it, which is possible. Otherwise, is there something else I need to do? - EricP.
Ah I see. well you might want to also include INTran. I typically use the related IN Graph when building Inventory transactions which has all related information and views in place. If you only update during the button for AddSerial then maybe just use the related graph? (INReceiptEntry for example). Otherwise I would include the 3 as views: INRegister, INTran, INTranSplit. They are already setup as PXParents in the DAC so just including them in the graph should resolve your issue (however might need to pull in the parent data to set the current INRegister and INTran) - Brendan

1 Answers

1
votes

Make sure you are including the parent views and setting current for INRegister and INTran as TranDate in the INTranSplit is based on INRegister.