Solved

Validation before save

  • 12 January 2024
  • 13 replies
  • 197 views

Userlevel 1
Badge

Hi. Can someone tell me the steps to apply validation message to the save button? I want provide a validation message when user click on save. It’s bit urgent. Thanks in advance.

icon

Best answer by Giri K 12 January 2024, 10:42

View original

13 replies

Userlevel 4
Badge +1

@ifelix 
In RowPersistingEvent of Header Table you can give Validation.

Userlevel 1
Badge

@ifelix 
In RowPersistingEvent of Header Table you can give Validation.

How to access this RowPersistingEvent ? Do i have to override a method called RowPersistingEvent? In override methods there wasn’t method as such. Therefore should i just write it in my code like this?

   public void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
{
baseHandler?.Invoke(cache, e);

ARInvoice row = Base.Document.Current;

throw new PXSetPropertyException("Your custom validation.", PXErrorLevel.Error);
}

 

Userlevel 4
Badge +1

@ifelix  when you click on Save Button, RowPersisting Event will trigger automatically.

 

 

public void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
{
baseHandler?.Invoke(cache, e);

//your validation

--------------------
--------------------
}
 

Userlevel 1
Badge

@ifelix  when you click on Save Button, RowPersisting Event will trigger automatically.

 

 

public void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
{
baseHandler?.Invoke(cache, e);

//your validation

--------------------
--------------------
}
 

It just saves without giving me any validation. I took this code from chatgpt. Can you provide me a proper code to make this work ?

 

This is the code i used.

 public void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
    {
        baseHandler?.Invoke(cache, e);
    
        //your validation
        throw new PXException("my validation");
    }

Userlevel 4
Badge +1

@ifelix Which screen you are working on?

Userlevel 1
Badge

@ifelix Which screen you are working on?

I am working on Sales Order Invoice Screen.

 

 

Userlevel 4
Badge +1

Try this

@ifelix 

public void ARInvoice_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
    {
     if (baseHandler!= null)
                baseHandler(cache, e);
           
        //your validation
        throw new PXException("my validation");
    }

Userlevel 1
Badge

Try this

@ifelix 

public void ARInvoice_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
    {
     if (baseHandler!= null)
                baseHandler(cache, e);
           
        //your validation
        throw new PXException("my validation");
    }

Thank you so much it’s working now.

Userlevel 1
Badge

hi @girik06 

 

So i used a confirmation message box on save. If user click yes then i want to proceed with save. If user select ‘no’ i want avoid saving. I get this error when i select no. “Error: Key field cannot start with a leading space.”

 

Here’s my code. How can i fix it ?

public void ARInvoice_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
    {
     if (baseHandler!= null)
                baseHandler(cache, e);
           
        WebDialogResult result = Base.Document.Ask("Confirmation", "Do you want to remove the hold?", MessageButtons.YesNo);

         if (result == WebDialogResult.No)
         {
             e.Cancel = true; // User clicked "No" in the confirmation dialog, cancel the save operation
         }
    }

 

Userlevel 4
Badge +1

you can write below code in NO condition
throw new PXException(“Save Cancelled”)

Userlevel 1
Badge

you can write below code in NO condition
throw new PXException(“Save Cancelled”)

Hi @girik06 

Thank you. It solved my issue.

Userlevel 1
Badge

hi @girik06 

 

So i used a confirmation message box on save. If user click yes then i want to proceed with save. If user select ‘no’ i want avoid saving. I get this error when i select no. “Error: Key field cannot start with a leading space.”

 

Here’s my code. How can i fix it ?

public void ARInvoice_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
    {
     if (baseHandler!= null)
                baseHandler(cache, e);
           
        WebDialogResult result = Base.Document.Ask("Confirmation", "Do you want to remove the hold?", MessageButtons.YesNo);

         if (result == WebDialogResult.No)
         {
             e.Cancel = true; // User clicked "No" in the confirmation dialog, cancel the save operation
         }
    }

 

hi @girik06 ,

So this method triggers on remove hold button as well. How can i make it work only for the save button ?

Userlevel 1
Badge

hi @girik06 ,

So this method triggers on remove hold button as well. How can i make it work only for the save button ?

This happens after i save the record only. Before saving everything works fine but once i save, the confirmation message which i wrote for the save button occurs on remove hold button as well. How can i stop this and make it happen only at the save button ?

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