Official Content

It is possible to allow end users of applications generated by GeneXus to select values and descriptions from a list of suggestions as they type. Even though these suggestions are loaded from attributes by default, you can use a Data Provider object to provide the suggestions instead.

The Data Provider object allows making a "Suggest" with data obtained from a service, and this component can rely on external sources. This feature is especially valuable in cases where the Panel object or Web Panel object do not have direct access to data through attributes, thus enriching the user experience by offering broader and more relevant selection options.

To achieve this, proceed as follows on objects for web applications or objects for native mobile applications:

  1. Set the appropriate properties
  2. Configure the Data Provider

1. Set the appropriate properties

You have two configuration alternatives for the attribute/variable for which you want to provide this functionality:

Or:

When the Data Source From property is set to Data Provider, the following properties are offered:

2. Configure the Data Provider

Make sure that the Data Provider object contains a Parm rule (defined in the rules section) that declares:

  • The parameters corresponding to those specified in the Parameters property in the same order as they were defined in that property.
  • In addition, the following last three parameters, in the following order:
    • &FilterOperator (string): Contains either "BeginsWith" or "Contains" values, depending on what was specified in the Filter Operator property of the control.
    • &Count (numeric): Contains the maximum number of records to be searched for.
    • &SearchText (string): Represents the text by which the user is trying to filter.

Since the Data Provider supplies the data used in "Suggest" to propose values to the end user, this data must be returned in the appropriate format:

  • Input Values and Input Descriptions: The data returned must be a list of input values (Input Values) or pairs of input values and descriptions (Input Descriptions).
  • Type Compatibility: Input Values must match the type of the variable associated with the control, which ensures that the data is consistent and usable. On the other hand, Input Descriptions must be of string type, such as Character or Varchar.
  • Parameter and Field Names: Although the specific names of the parameters or fields returned are not crucial, the data types must be correct. This means that the Data Provider can use different names for the values and descriptions, as long as the data types conform to the above.

Sample

Consider an application called LightCRM, which enables end users to schedule Meetings with a certain Contact of a Company. To schedule a new meeting, among other things, the Company name must be indicated as well as the Contact with whom the meeting will be held. Suppose you want to display, on the web or native mobile application, a Dynamic Combo Box with the Company’s Contacts which should be ordered by birth date.

To solve this requirement, you need to use the Data Provider object as the data source for the controls to be used. Then, follow the steps below:

1. Create an SDT

First, create a Structured Data Type (SDT) object and name it “ContactsSDT”.

Indicate the SDT is a collection by selecting the Is Collection checkbox, and define the ContactId and ContactName members as follows:

DataSourceFrom_ContactsSDT_v18u5

2. Create a Data Provider

Create a Data Provider object as follows:

Rules section:

Parm(CompanyId, &FilterOperator, &Count, &SearchText);

Source section:

ContactsSDT
{
    ContactsSDTItem [Count = &Count]
    order ContactBirthday
    Where ContactName like &SearchText when &FilterOperator  = !'BeginsWith'
      Where ContactName like !'%' + &SearchText when &FilterOperator = !'Contains'
    {
        ContactId = ContactId
        ContactName = ContactName
    }
}

Availability

This functionality is available since GeneXus 18 Upgrade 5.

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant