Solved

How bad is running queries in RowSelected?

  • 6 February 2023
  • 6 replies
  • 103 views

I would like to check if Credit Memos or Prepayments exists when loading an Invoice. How programmatically incorrect is it to query the database on RowSelected? (I know you’re not supposed to make changes in RowSelected).

icon

Best answer by Shawn Burt 6 February 2023, 20:29

View original

6 replies

Userlevel 5
Badge +1

I think its preferential to do it in RowSelecting. It will depend on what you are doing with the results.

If you are changing things like enabled or visibility you may need to create an unbound extension so you can set a flag to be used in RowSelected. This would limit the number of times you are running that query. 

So taking this advice, I moved the queries to RowSelecting and update two unbound decimal fields with a sum of the result.

Then, in the RowSelected event, I am getting the value of the unbound fields and determining if actions should be shown based on the result. However, it doesn’t seem like the values are sticking across to the RowSelected event. It seems like it probably should be, but I’ve not worked with these much in conjuction with each other.

@Shawn Burt - Is this what you were suggesting?

Userlevel 5
Badge +1

yep :)

Badge +11

Ok, I switched to using e.Cache.GetValue instead of e.Cache.GetValueExt and now it sticks. Thanks!

I have one more issue: there are a few situations where the RowSelected event is called (saving for instance), where my code ran before but now does not. I would like to check if the values gotten in RowSelected are null, indicating that RowSelecting has not run, and then call it, but I can’t find ANY documentation anywhere on how to use this. Maybe that’s because it’s a horrible idea, but I guess I need some additional direction.

I think I resolved this. I moved the selects to a private method that gets called from RowSelecting. That way, in the same situation where I would manually raise RowSelecting, I can just call the private methods. Still executes BQL in RowSelected, but in a much reduced fashion.

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