Using Search to find something in a Smartobject?

  • 26 January 2015
  • 8 replies
  • 4 views

Userlevel 3
Badge +16

Hi,

 

I'm trying to see whether it is possible to create a Search Feature on a View to look for "Search Terms" within a Smartobject. 

 

For example, in the Smartobject, I have several fields, and I'd like to implement a feature where the user can enter a search term (either a search term alone or pick a field to filter the result) then for K2 to return all Records containing that string and then allow the user to double-click on a result to bring up the Record, anyone know if this is possible?

 

Thanks.

 

 


8 replies

Userlevel 1
Badge +8

Hi Sharpharp1

 

There are a couple of options I can think of here.

 

First is to use the advanced filter option of a SmartObjects list method. In the Filter tab of the method configuration select Advanced and then use the "Contains" operator. This will work for searching on a single field with a single parameter.

 

The other option is to create and expose a SmartObject method to do the search and return results. For example, if your SmartObject is based on a SQL server database table, then you can create a stored procedure that takes a parameter(s) and then returns the search results in a List (using the parameters in the SQL where clause).

 

 

Userlevel 3
Badge +16

Hi Andrew,

 

Thanks for thr suggestions, my data is all kept in a Single Smartobject which is then saved as an SQL Table, so I like the idea of the STored Procedure you mentioned.

 

Have you got a step by step on how to achieve this?

If the user can enter a search term and it comes back with a list, then that would be great. Then the user simply double-clicks the require search result from that returned list and make it bring up the entire record in a view?

 

Thanks

Userlevel 1
Badge +8

Sharpharp1

Your actual implementation will depend on what you want to search on (i.e. 1 or multiple fields, different data types, starts with, contains etc). Below is an example searching a Customer table by CustomerName. This will return any customers where any part of the name matches the search string.

1. Create a stored procedure that performs the search. Your stored procedure query might look like:
      SELECT * from dbo.[Customer] Where CustomerName like '%' + @SearchParameter + '%'

2. Open SmartObject Tester and refresh the service instance for the SQL server database
3. Open K2 Designer and edit your SmartObject
4. Add a new method and select the new stored procedure under the SQL database service object
5. Name the method and then map the properties. Create a SmartObject method parameter to map to the stored procedure parameter
6. Save the SmartObject
7. Test using SmartObject tester and then implement in your View

 

Good luck and let me know if you need further help.

Userlevel 3
Badge +16

Hi,

 

Daft me is stuck at step 1) How do you create a stored procedure? I can follow steps 2 onwards, but i've never created a Stored Procedure before.

 

Only thing i can find is: http://help.k2.com/onlinehelp/k2blackpearl/userguide/4.6.6/webframe.html#stored_procedures.html

but that doens't make much sense...

 

Can you explain a bit deeper on how to achieve this please?

Userlevel 1
Badge +8

Hi Sharpharp1

 

If you are not familiar with stored procedures then I suggest you speak to your DBA or whoever maintains your SQL database(s). Stored procedures are not created within the K2 environment - it must be done using SQL Server tools (e.g. SQL Server Management Studio). If it is not a custom SQL database (i.e. is the backend database for one of your LOB systems) then you may not be permitted to create stored procedures on that database.

 

Can I suggest you look at the first option I suggested - the advanced filter. When you are configuring the List method in the SmartForm rules you can select Advanced on the Filter tab and pass in the filter value. For example you can pass in the search value and use the "Contains" operator to get all Customer Names that contain the search value.

Userlevel 3
Badge +16

Hi,

 

As you suggested, I will stick with option one.

 

I am looking at my Editable List and have the List Method set to Get List.

I have added a text box and a button

 

Then i did a rule on button click to do a smartobject method get list.

filter i picked a single field and say CONTAINS my text box

I then added all the other fields as well to CONTAINS my text box as well.

 

This works and returns all records which contain the text

Any ideas how i get it so that the user can select which field to search on?

 

 

Thanks

Userlevel 1
Badge +8

Sharpharp1

 

Have you tried using the inbuilt listview Filter? This will allow the user to select the field/column and enter the search term.

 

To enable it on a listview click the Configure View Settings button (the little cog icon) and select Enable Filter.

 

Limitiation of this is you can only search on one field at a time.

 

I don't think you can use the advanced filter option if you want the user to select the field to search on. The field and search value must be set at design time.

 

 

Userlevel 3
Badge +16

Tried using the built-in filter but that crashed k2 designer, as you say it might be because i'm using both.

 

I'll stick with doing a search for all fields, which is fine for now.

 

Thanks for your help with this Andrew!!!

Reply