Skip to content

OnFindSuggestions - cWebSuggestionForm

Event called to fill a suggestion list. This is called each time the contents of the list needs to change

Type: Event

Parameters

Parameter Type Description
sSearch String The current search value, sSearch (which is whatever the user has currently typed)
ByRef aSuggestions tSuggestion[] Returns a tSuggestion struct array, where each item in the array represents a line in the suggestion list

Syntax

Procedure OnFindSuggestions String sSearch ByRef tSuggestion[] aSuggestions

Description

OnFindSuggestions is called in response to the user changing the search target. Each time the user types in a character, the suggestion list needs to change. This is handled by calling OnFindSuggestions.

Normally, the process of filling this list is automatic and you do not want to change it. When peSuggestionMode is smFind or smValidationTable, you will probably not want to augment this event.

When peSuggestionMode is smCustom, you will need to augment this event to provide a list of suggestions. See peSuggestionMode for more information about changing this event as well as the OnSelectSuggestion event, which you will also need to augment.

Sample

This sample shows how to customize OnFindSuggestions (in the Customer Name cWebSuggestionForm object in the DemoSuggestionForm.wo in the WebOrder Sample workspace) to search both the Customer_Number and Name columns in the Customer table when the user types into the form.

The sample is a bit contrived, since Customer.Customer_Number is a numeric column and thus only allows numeric data. But if you type a 2 into the sample after making this change, it will find all Customer records where either the name or number contain a 2.

Use cWebSuggestionForm.pkg

Object oWebSuggestionForm1 is a cWebSuggestionForm
    Entry_Item Customer.Name
    Set piColumnSpan to 7
    Set psLabel to "Customer Name:"
    Set piStartAtChar to 1
    Set piFindIndex to 2

    Procedure OnFindSuggestions String sSearch tSuggestion[] ByRef aSuggestions
        Integer i
        Move (SizeOfArray(aSuggestions)) to i
        Clear Customer
        Repeat
            Find gt Customer by 2  // Name Customer_Number
            If (Found) Begin
                If (Customer.Customer_Number contains sSearch or lowercase(Customer.Name) contains Lowercase(sSearch)) Begin
                    // return the rowid
                    Move (trim(Customer.Customer_Number)) to aSuggestions[i].sRowId

                    // add both customer number and name to the list of suggestions that are shown to the user
                    Move (trim(Customer.Customer_Number)) to aSuggestions[i].aValues[0]
                    Move (trim(Customer.Name)) to aSuggestions[i].aValues[1]
                    Increment i
                    If (i >= piMaxResults(Self)) Move False to Found  // stop at piMaxResults
                End
            End
        Until not (Found)
    End_Procedure
End_Object