Question

RowPersisting event on Save button

  • 17 January 2024
  • 9 replies
  • 221 views

Userlevel 1
Badge

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

Userlevel 5
Badge +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:

 

Userlevel 1
Badge

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.

 

Userlevel 4
Badge +2

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.

Userlevel 6
Badge +4

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

Userlevel 1
Badge

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 ?

Userlevel 1
Badge

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.

Userlevel 4
Badge +2

@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.

Userlevel 1
Badge

@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 ?

Userlevel 7
Badge

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

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