Solved

Event handlers comprehension

  • 30 June 2023
  • 5 replies
  • 233 views

Userlevel 3
Badge

Hi,

I have a probably stupid and basic question about how events are handled in Acumatica.

Let’s suppose we have a graph class (say G1) using a given DAC (say D) in its main view, and an other graph class (say G2) using also DAC D in its main view. In this example, we assume that G1 and G2 haven’t any link them (I mean that G1 is not an extension of G2 for instance).

If a change occurs for one of the field in an instance of DAC D throught the screen associated to graph G1, the D_RowUpdated event handler method is called as expected if this method has been added in class G1. That’s OK.

However, I have noticed that if the D_RowUpdated event handler is also present in class G2, it is not called on field change occuring in G1, as if G2 would not be aware of what’s happening in G1. Maybe it is due to the fact that the two graphs don’t share the same caches.

How to refresh views in G2 on row updating occuring in G1 ?

icon

Best answer by ygagnaire12 30 August 2023, 08:40

View original

5 replies

Userlevel 5
Badge +1

@ygagnaire12 

In Acumatica, event handlers are associated with the specific graph where they are declared. The events in one graph will not automatically trigger event handlers in another graph, even if they both operate on the same DAC. This is by design, as it allows for separation of concerns and ensures that each graph can operate independently.

However, there are times when you might want to synchronize or communicate between graphs. There are several ways to achieve this:

  1. Use static events: If you need to share events across multiple graphs, you can declare static events in a common class and have the graphs subscribe to those events. When the event is triggered in one graph, all subscribed graphs will receive the notification.

  2. Explicitly call methods in another graph: You can create an instance of another graph and call its methods directly. This approach is suitable when you need to perform a specific action in another graph.

  3. Shared Cache: If both graphs are working with the same data, you can use the shared cache feature to synchronize data between graphs. This feature allows you to share the same cache instance between graphs, so changes made in one graph will be immediately visible in another graph.

  4. PXSignal: Acumatica has a class called PXSignal that you can use to send a signal from one graph to another. You can define a PXSignal object in one graph and call its Send method to notify another graph.

  5. Custom Messaging Mechanism: You can implement your own messaging mechanism to communicate between graphs. For example, you can use events, delegates, or other patterns to send messages between graphs.

In your scenario, where you want to refresh views in graph G2 when a row is updated in graph G1, you can use the shared cache feature or the PXSignal class to notify G2 about the change. Alternatively, you can create an instance of G2 in the event handler of G1 and call a method in G2 to refresh the views.

Userlevel 3
Badge

Hi @davidnavasardyan09,

Thanks a lot for your very clear explainations ! I had tought creating a graph of G2 in the event handler of G1 and call G2 refresh views but the other tracks you have suggested are interesting.

Concerning shared Cache (this is indeed one of the best way for us to processed) and use of static events, I am struggling to find informations on the implementation. Would you have some technical details about the way to implement theses features ?

Thx.

Userlevel 3
Badge

Hi @davidnavasardyan09 ,

Would you have some technical precisions about the way to used  shared cache feature to synchronize data between graphs (link to documentation, forum...) ? 

Thx.

 

  1. PXSignal: Acumatica has a class called PXSignal that you can use to send a signal from one graph to another. You can define a PXSignal object in one graph and call its Send method to notify another graph.

I don’t believe  PXSignal actually exists in the codebase, as far as I know.  This answer seems a bit vague and possibly AI generated?  Anyway, @ygagnaire12, how does graph G2 relate to the screen?  Typically the graph being used is specified in the ASPX for the page, specifically via the  PXDatasource control, which binds the ASPX page to the graph.  Also, are these graphs you have created?  Is there a specific reason they need to be separate graphs?

Userlevel 3
Badge

Hello @Goldsum,

After various attempts, I came to wonder, as you point out, about the interest of separating these two graphs. The best way is probably to merge the two classes I have created and this will solve my problem. Thank you for your help !

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