Hi @travisk91 ,
For the rare case where you need to edit the value from the UI, the cleanest approach is to make the string display field editable and write the parsed value back to the underlying Int64 field via the setter:
#region UsrExternalKeyDisplay
[PXString(20, IsUnicode = false)]
[PXUIField(DisplayName = "External Key")]
public virtual string UsrExternalKeyDisplay
{
get => UsrExternalKey?.ToString();
set
{
if (long.TryParse(value, out long parsed))
UsrExternalKey = parsed;
}
}
public abstract class usrExternalKeyDisplay : PX.Data.BQL.BqlString.Field<usrExternalKeyDisplay> { }
#endregion
This way the user types the 16-digit value as a string, and the setter validates and converts it back to Int64 before saving. The actual DB field (UsrExternalKey) remains Int64 — nothing changes in your data model.
A couple of things to keep in mind:
Remove the Enabled = false from PXUIField so the field becomes editable.
Optionally add a PXUIVerify or validation in FieldVerifying to reject non-numeric input and give the user a clean error message.
You can also remove the PXFormula attribute from Rakshanda’s example if needed, since the getter/setter handles the sync directly.
Hope that covers it!