I have successfully set up a field on the Customers Default Address to flag if the address is verified. On the Customers screen adding a FieldUpdated event for AddressLine1 allowed me to reset this flag if the field was edited.
This is the code:
protected void Address_AddressLine1_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (Address)e.Row;
if (row == null) return;
var addrExt = PXCache<Address>.GetExtension<AddressExt>(row);
if (addrExt?.UsrAIAddressVerified == true)
{
cache.SetValueExt<AddressExt.usrAIAddressVerified>(row, false);
}
}This works great on the Customers screen. If I edit Address Line 1 and tab away it resets the flag. I want to reproduce the same thing on the Shipping Address on the Sales Order Screen.
I added the following:
protected void SOShippingAddress_AddressLine1_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (SOShippingAddress)e.Row;
if (row?.AddressID == null)
return;
// Fetch SOAddress record by AddressID
var soAddress = PXSelect<SOAddress,
Where<SOAddress.addressID, Equal<Required<SOShippingAddress.addressID>>>>
.Select(Base, row.AddressID).TopFirst;
if (soAddress != null)
{
var soAddrCache = Base.Caches<SOAddress>();
var addrExt = PXCache<SOAddress>.GetExtension<SOAddressExt>(soAddress);
if (addrExt?.UsrAIShipAddressVerified == true)
{
soAddrCache.SetValueExt<SOAddressExt.usrAIShipAddressVerified>(soAddress, false);
soAddrCache.Update(soAddress); // make sure change is tracked
}
}
}When I debug this and add a breakpoint inside the function it never triggers when I type into the Address Line 1 field of the Shipping Address. Am I missing something obvious? It does trigger if I click the override address button but doesn’t reset the flag.
Any help would be gratefully received,
Phil