Solved

FieldVerifying custom fields on DAC extension

  • 8 December 2022
  • 3 replies
  • 156 views

Userlevel 4
Badge

Hi,

I have a simple piece of code calling field verifying that does not quite produce the required behaviour.  

The custom field in question sits in a DAC extension to SOShipment (SOShipmentExt) and is called usrSealNo.  Essentially all I am looking to do is raise an error if the value in this field has been used on any other Shipments (and prevent the record from being saved until a unique usrSealNo is provided). 

The code in place is:

Now, when  a value is entered into the field that already exists on another Shipment, the Field Verifying event seems to raise the exception OK:

However,  the user is still able to save the record despite the error being raised.

I have other FieldVerifying events in my customisation that do prevent a user saving when the  Error exception is raised.  The difference seems to be that they are on fields that are in a custom DAC, not a DAC extension.

Is there some trick to Verifying custom fields in DAC extensions?

Thanks in advance for any help on this,

John.

 

 

 

icon

Best answer by JWS539 8 December 2022, 19:54

View original

3 replies

Userlevel 7
Badge +17

Hi @JWS539  You can invoke the fieldverifying event from the persist method like below, so that system will not save the document.

   public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate del)
{
if(Base.Document.Current != null)
{


object val = Base.Document.Current.GetExtension<SOShipmentExt>().UsrSealNo;
Base.Document.Cache.RaiseFieldSelecting<SOShipmentExt.usrSealNo>(Base.Document.Current, ref val, true);

}
del();
}

 

Userlevel 4
Badge

Hi Naveen,

 

Thank you for taking the time to review and respond to my question.  I made one change to the code you provided to get this to work.  The RaiseFeildSelecting didn’t appear to trigger anything (possibly because the value specified was the same as what was already in the field?).  However, replacing this line with RaisingFieldVerifying worked, so problem solved. 👍

Also, good to understand that you can explicitly force events to fire in certain situations, good to know.

Modified Code:


public delegate void PersistDelegate();
        [PXOverride]
        public void Persist(PersistDelegate del)
        {
            if (Base.Document.Current != null)
            {
                object val = Base.Document.Current.GetExtension<SOShipmentExt>().UsrSealNo;
                //Base.Document.Cache.RaiseFieldSelecting<SOShipmentExt.usrSealNo>(Base.Document.Current, ref val, true);
                Base.Document.Cache.RaiseFieldVerifying<SOShipmentExt.usrSealNo>(Base.Document.Current, ref val);
            }

            del();
        }


 

Thanks for your help,

John

 

 

Userlevel 7
Badge +17

Hi @JWS539  Yeah, it’s a typo. we should use FieldVerifying.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved