mardi 13 mars 2007

How-To: Run a Quick Search from a Client Script

Detail
If there is a button that triggers a series of steps, sometimes it is useful to have the user choose some data that will then be used later in the client script, or in an ASR.

Resolution
There are three steps required for this functionality to be used. The first is to build the QuickSearch in the client script and launch it. The second is to add a global variable to handle the returned results. The third is to trap the user's selection so that the selected item can be passed back.

1) the code to include in the client script should be something like:

Dim objSearchFactory
Dim vntCompanyId

Set objSearchFactory = UIMaster.CreateCenterReference("quicksearch")
objSearchFactory.Options.DefaultTab = 1
objSearchFactory.SearchType = 1
objSearchFactory.MultiSelectMode = mulselNone

Global.vntRegistrationId = Null
UIMaster.ShowQuickSearchModalEx UIMaster.RSysClient.GetTable("Company").TableId, objSearchFactory
vntCompanyId = Global.vntCompanyId

2) On a global client script (I usually use Global_Search) a global variable should be declared at the top like so:

Dim vntCompanyId

3) In the event OnSearchResultsItemClick() the following code should be included:

Dim SearchName
SearchName = ""
Dim RowNumber
If UIMaster.RUICenter.SearchType = 1 Then
SearchName = UIMaster.RUICenter.Search.SearchName
End If
If SearchName = "Company_QuickSearch" Then
If UIMaster.RUICenter.IsModal Then
vntCompanyId = UIMaster.RUICenter.SearchEventObj.Value
OnSearchResultsItemClick = True
UIMaster.CloseWindow()
End If
End If

Some notes:
- Change the table name in GetTable to your desired table to search and change the Search name to 'MyTable_QuickSearch'
- It is important to only run the code in the eventhandler if IsModal = true, or it will interfere with your regular QuickSearches.
- A recordset of multiple records can be returned if objSearchFactory.MultiSelectMode = mulselNone is changed to objSearchFactory.MultiSelectMode = mulselBoolean. The code to handle the results would have to be changed accordingly.

Aucun commentaire: