Skip to main content

Hi all, happy new year!

 

I'm trying to create a query that allows the user to select from a list box and run a query based on the selection.  Can anyone help me with this?

 

 

Hi Taffy_Lewis,

 

In order to assist here, We are going to need a bit more detail.  Can you describe the use case in full?  Are we attempting to query SQL or another system?  What will the data selected in the list box be, and where will that come from?

 

Regards,

 

Mike


Ok Mike, thanks for your reply,

 

The user is presented with a series of check boxes from a check box list control, about 15 choices.  The user selects 5 of the 15.  I now want to be able to send a query statement that uses the 5 selections in the where statment, that is, "....select * where field = (1 selection) or (2nd selection) or (3rd selection) or (4th selection) . .. "

 

Thanks again!

 

Taffy


Ok, looks like the values in the checkbox list control can be captured as xml.  Looks like I'll have to parse the values and then pass them to the backend sql.  Found this answer in this thread.

 

http://community.k2.com/t5/K2-blackpearl/Save-records-from-checkbox-list-selection/td-p/59277/page/2

 

Thanks again for the input!

 

Taffy


There is a much, much easier way to do this via a smartobject interacting with SQL.  I'll try to get an example together for you later today/tomorrow.

 

Regards,

 

Mike


That would be great!  I'll take all the help I can get!  :)

 


Taffy_Lewis,

 

It's been a bit of a crazy week here, and I haven't gotten a chance to put something together for this specific case, but I'll give you the view from 35,000 feet as it may help you get started.

 

Basically, you want to create a smartobject to interact with the SQL table you're trying to query.  Once you have that, there's several options.  Right off the bat, you could create a list view based on that smartobject, and then use checkboxes to filter the results, you'd be bringing the entire table back via that smartobject and executing a simple list method.  From there, your checkboxes act to filter the list.


Now if you're dealing with a large ammount of data, you'd basically follow the steps above, set up your checkboxes, and use the values in those checkboxes to narrow down the search, and then use those values to fire the method to return more specific data.  You shouldn't have to do anything external to K2 to do this, like setting up a query to be executed, the smartobject should handle it all, you'll just pass it values via the state of the checkboxes.

 

I'll try to put a more detailed example together early next week.


Regards,


Mike


Mike,

 

Are you saying to use the value of the checkbox list control in the filter section of the the smartobject get list method call? When we try to do that we get an error, because it doesn't understand the XML returned by the checkbox list control.

 

If you could provide a simple example that would be great.

 


Hi Taffy_Lewis,

 

I'm thinking of logic such as:

IF(PotatoBox.ischecked)  filter by "potato"
ElseIF(TomatoBox.ischecked) filter by "tomato"

 

You don't need the XML from it, you're looking more for a boolean state to trigger a filter on a specific value.

 

When you implement the filter, you have two options.

1. SQL friendly - filter on client side and just return the whole list. (SQL gets hit once, returns entire list, then is filtered via smartforms control)

2. Client side friendly - pass the filters to the SQL smartobject to create the query.  (every time list filter is changed, SQL gets hit)

 

Option 1 sounds like less work, and probably a better idea.  An even cooler idea would be to use a "multi select" type of control, that pulls possible values for the filter based on the data in SQL first, then allows the user to select which ones they wish to filter on.  That may even be easier than implementing checkboxes and logic behind them, and certainly more dynamic, as if a "new" category shows up somewhere, a filter option will instantly exist for it.

Regards,


Mike


Mike,

 

What I think your saying is a solution would be to separate the items in the checklist (in our case there are 25 items loaded into the check list from a db call) the on a call to the smart object within event rule do something like (If control is blank, filter) and then have an if for each control? 

 

i'm not following the second option.

 

Taffy


Here is an example scenario. Suppose we have a list of addresses which include a field for state. We want to allow the user to be able to select multiple states and filter the list of addresses to just those states. For example the user selects states NY, NJ, and CA and the addresses list is filtered to show the addresses in those 3 states. The user can select as many states as they wish to filter by.


Reply