Conditionally displaying a list view if it contains results

  • 13 October 2014
  • 6 replies
  • 1 view

Badge +4

I am trying to conditionally display a view on a SmartForm. The view is connected to a List event of a SmartObject from a SQL database.

 

I start off with the view set to not visible and then in the form initalization event I want to check if the view has values and then display it if it does.

 

I tried adding a Count aggregation to the list view and then testing for the value not being = 0. If it is true, then I Show the view. The aggregation comes back correctly but the Condition doesn't evaluate. If I 'Show a message' to the user with the value of the aggregation before doing the test, then it works. If I take the 'Show message' out then it stops working again. I tried putting the condition in the 'Initialized' method instead of Initializing, but that didn't help either.

 

Can anyone tell me the best way to achieve the desired behaviour please?

 

Thanks

 


6 replies

Badge +5

There might be some information in this help file. I've not had a chance to fully look into it though.

help.k2.com/files/4718

Badge +8

I might be wrong, but I think your rendering your view in a way that may cause more overhead.


 


Can you provide more information on the loading of your view?  I will commonly create a New and Exisiting rule event that will either make my controls empty for input or populated wtih the values of my backend data.


 


You shouldn't need a list view to load data on your controls.  You should be able to fire the load event and put in a unique ID related to the row data. 


 


For example, if I have an employee table from sql and it has first, last name, address.  If I were to load ID 1 from that table, I'd get back those values so that I can load them into SmartForm controls.

Badge +4

Thanks for the replies. I have attached a screen shot which might make it easier to understand the issue.

 

The strange thing is that the method using the aggregation works if there is a user interactiion via the message box. So I am wondering if it is a timing issue.

 

However, if there is a better way, I'd love to understand it.

 

Cheers


15990iF901C55C30998515.png
Badge +8

Actually the screen shot looks different than what I was thinking you were trying to accomplish.  Your right on the timing issue, it's hard to evaluate the timing when we can only see the screens.


 


I would design that form with the view initially hidden (you may have already done) then right off the bat have your rules go out and test to see if that user is a manager.  If you want all managers to be able to view, the best way is to fire a list event against ad users "GetUsers with the user as a criteria in the manager text box."  If they are a manager, the list event will return their name.


 


This will be configured from your From Initialized rule:


 11194iA91B3A1EA6528D6D.png


 


So the next rule would be a condition to test to see if this control has data.  If it has data then Show your view.


 


Let me know if that does or does not make sense.


 

Badge +4

Hi,

 

thanks for the reply. Yes it makes sense. However I am not looking to see if they are a manager, I am doing a SQL query for all records where the 'Manager' column is equal to the current user network id. I only want a list of records for people that report to the current user.

 

I am starting off with it hidden and then trying to show it if there are results in that list. But because of the timing issue, it doens't display unless I put the prompt up first.

 

I am wondering if I am going to have to do another smartobject query against a stored proc to get the number of results in order to decide whether to display the view. It is a bit redundant though and I would prefer not to.

 

Cheers

 

 

Badge +4

So I have worked out that if I force the view to initialise directly before checking the count value in the aggregation, that it does then work.

 

Cheers

Reply