Skip to main content
Question

RowPersisting event on Save button


Forum|alt.badge.img

Hello, I am using RowPersisting event to pop up a confirmation message when user click on save button. This works fine until i save a record. After i save the record, the confirmation message pops up even when i click on Remove hold button. I just want the pop up message to occur only at the save button. Before saving anything it works fine. Nothing pops up when i click remove hold button. But only after the record is saved, the pop up message occurs at the click on remove hold. How can i fix this ? I only want the confirmation message to occur at the save button click even after saving.

This is my code

public void ARInvoice_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting baseHandler)
    {
     if (baseHandler!= null)
                baseHandler(cache, e);

        ARInvoice invoice = (ARInvoice)e.Row;

        if (invoice != null && (e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update))
        {
            WebDialogResult result = Base.Document.Ask(
            "Confirmation",
            "Please confirm the Freight Surcharge Amount. ",
            MessageButtons.YesNo,
            MessageIcon.Question);

            if (result == WebDialogResult.No)
            {
                //e.Cancel = true; // User clicked "No" in the confirmation dialog, cancel the save operation
                throw new PXException("Save Cancelled");
            }
          Base.Document.Cache.IsDirty = true;
        }
    }

 

9 replies

andriikravetskyi35
Jr Varsity I
Forum|alt.badge.img+1

hi @ifelix 

You might override Handler method of PXSave action on screen like this:

  public class PXSaveMyAction<T> : PXSave<T> where T : class, IBqlTable, new()
  {
      public PXSaveMyAction(PXGraph graph, string name) : base(graph, name) { }

      [PXUIField(DisplayName = "Save", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
      [PXSaveButton]

      protected override IEnumerable Handler(PXAdapter adapter)
      {
          if (ToSave(adapter))
          {
              return base.Handler(adapter);
          }
          else
          {
              throw new PXException("Save Cancelled");
          }

      }

      private bool ToSave(PXAdapter adapter)
      {
          ARInvoice invoice = adapter.Get().RowCast<ARInvoice>().FirstOrDefault();

          var graph1 = adapter.View.Graph as ARInvoiceEntry;

          WebDialogResult result = graph1.Document.Ask("Confirmation", "Please confirm the Freight Surcharge Amount. ", MessageButtons.YesNo, MessageIcon.Question);

          if (result == WebDialogResult.No)
          {
              return false;
          }
          graph1.Document.Cache.IsDirty = true;
          return true;
      }
  }

  public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
  {
      public static bool IsActive() => true;

      public PXSaveMyAction<ARInvoice> Save;

  }

 

here is screen shot from my local instance, I hope it will help:

 


Forum|alt.badge.img
  • Author
  • Freshman I
  • 21 replies
  • January 17, 2024
andriikravetskyi35 wrote:

hi @ifelix 

You might override Handler method of PXSave action on screen like this:

  public class PXSaveMyAction<T> : PXSave<T> where T : class, IBqlTable, new()
  {
      public PXSaveMyAction(PXGraph graph, string name) : base(graph, name) { }

      [PXUIField(DisplayName = "Save", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
      [PXSaveButton]

      protected override IEnumerable Handler(PXAdapter adapter)
      {
          if (ToSave(adapter))
          {
              return base.Handler(adapter);
          }
          else
          {
              throw new PXException("Save Cancelled");
          }

      }

      private bool ToSave(PXAdapter adapter)
      {
          ARInvoice invoice = adapter.Get().RowCast<ARInvoice>().FirstOrDefault();

          var graph1 = adapter.View.Graph as ARInvoiceEntry;

          WebDialogResult result = graph1.Document.Ask("Confirmation", "Please confirm the Freight Surcharge Amount. ", MessageButtons.YesNo, MessageIcon.Question);

          if (result == WebDialogResult.No)
          {
              return false;
          }
          graph1.Document.Cache.IsDirty = true;
          return true;
      }
  }

  public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
  {
      public static bool IsActive() => true;

      public PXSaveMyAction<ARInvoice> Save;

  }

 

here is screen shot from my local instance, I hope it will help:

 

 Hi @andriikravetskyi35 ,

I checked your code on mine but still when i click on the remove hold action button on my screen i get this confirmation message which is supposed to come only at the save click. You can check it on your screen as well. Just click yes in the confirmation message. Then your records saves. After that try clicking on Pay action button. The same confirmation message will occur there as well.

This is a saved record. When i click on remove hold, i get the confirmation message. I dont want that to happen. I only want the confirmation message to come on save click.

 


Patrick Chen
Jr Varsity III
Forum|alt.badge.img+2
  • Jr Varsity III
  • 51 replies
  • January 17, 2024

Do you mean you only want the dialog message to pop when you’ve first saved the document? If so, you should only pop the message when e.Operation == PXDBOperation.Insert and not when the operation is Update.  If you want it to pop after every save then that’s a problem since removing the hold changes the status of the document and requires a save.


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+4
Patrick Chen wrote:

Do you mean you only want the dialog message to pop when you’ve first saved the document? If so, you should only pop the message when e.Operation == PXDBOperation.Insert and not when the operation is Update.  If you want it to pop after every save then that’s a problem since removing the hold changes the status of the document and requires a save.

Hi @ifelix 

@Patrick Chen is the solution on persisting event. It will work only the first time when the record is going to be created in the DB


Forum|alt.badge.img
  • Author
  • Freshman I
  • 21 replies
  • January 18, 2024
Leonardo Justiniano wrote:
Patrick Chen wrote:

Do you mean you only want the dialog message to pop when you’ve first saved the document? If so, you should only pop the message when e.Operation == PXDBOperation.Insert and not when the operation is Update.  If you want it to pop after every save then that’s a problem since removing the hold changes the status of the document and requires a save.

Hi @ifelix 

@Patrick Chen is the solution on persisting event. It will work only the first time when the record is going to be created in the DB

Hi @Leonardo Justiniano , @Patrick Chen 

How Can i make it work after the record is created in the DB ? How can i stop the pop up from occurring on remove hold button after the record is saved ?


Forum|alt.badge.img
  • Author
  • Freshman I
  • 21 replies
  • January 18, 2024
Patrick Chen wrote:

Do you mean you only want the dialog message to pop when you’ve first saved the document? If so, you should only pop the message when e.Operation == PXDBOperation.Insert and not when the operation is Update.  If you want it to pop after every save then that’s a problem since removing the hold changes the status of the document and requires a save.

Hi @Patrick Chen ,

I want the pop up to occur after every save on the save click. Not on Remove hold click.


Patrick Chen
Jr Varsity III
Forum|alt.badge.img+2
  • Jr Varsity III
  • 51 replies
  • January 18, 2024

@ifelix   Ok, Removing Hold click has a Save packaged in I’m afraid.  What you could do depending on your business requirements is test your invoice for status in your code above.  Perhaps your pop up should only execute when the invoice.Hold = true.


Forum|alt.badge.img
  • Author
  • Freshman I
  • 21 replies
  • January 19, 2024
Patrick Chen wrote:

@ifelix   Ok, Removing Hold click has a Save packaged in I’m afraid.  What you could do depending on your business requirements is test your invoice for status in your code above.  Perhaps your pop up should only execute when the invoice.Hold = true.

In acumatica is it possible to check the condition as if remove hold button is clicked or not ?


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2754 replies
  • March 18, 2024

Hi @ifelix were you able to find a solution? Thank you!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings