Skip to main content
Question

Error: Key field cannot start with a leading space.

  • February 13, 2026
  • 1 reply
  • 0 views

Forum|alt.badge.img

Hello everyone,

We have an inventory item with the tracking method set to “Track Serial Numbers”, which allows users to manually enter serial numbers.

We recently added a feature for some inventory items to auto-generate serial numbers from a numbering sequence on the Save action.

However, when trying to assign the generated serial number to the Lot/Serial Number field during Save, we encounter the following error:

“Key field cannot start with a leading space.”

We are confident that the serial number generated from the numbering sequence does not contain any spaces.

Could someone advise on the correct approach to assign auto-generated serial numbers to serial-tracked inventory items on Save without triggering this error?

Thank you in advance!

 

protected virtual void POReceiptLine_RowPersisting(PXCache sender, PXRowPersistingEventArgs e, PXRowPersisting BaseEvent)
{
    BaseEvent.Invoke(sender, e);

    var lineitem = (POReceiptLine)e.Row;

    if (lineitem == null)
        return;

    if (Convert.ToString(e.Operation) == "Normal, Insert" || Convert.ToString(e.Operation) == "Normal, Update")
    {
        string serialNbr = AutoNumberAttribute.GetNextNumber(sender, lineitem, numSeq, Base.Accessinfo.BusinessDate);

        Base.transactions.SetValueExt<POReceiptLine.lotSerialNbr>(lineitem, serialNbr);      
    }
}

1 reply

Forum|alt.badge.img+3

Hello ​@ckwiat46 I think may be RowPersisting is too late, by the time RowPersisting runs, Acumatica has already validated.
You can try with RowInserting or RowUpdating on the Split. its rely on POReceiptLineSplit.

 

hope it helps.