SearchPickerField ignores Datasource query.

Hello! I’m having a problem with using a SearchPickerField. I have set up a CollectionDatasource with a query and am using it as the optionsDatasource of the SearchPickerField. When I look at the items within the datasource, they correspond to the query correctly, but when I click on the picker field and the lookup screen pops up, it has all the instances of the entity specified in the options datasource and completely ignores the query. Am I missing something? I’ve tried creating a datasource programmatically, creating a datasource in studio and then feeding it a desired query string in code, and creating a datasource in studio, setting up a filter and refreshing the datasource in code supplying a map of custom parameters.

Hi Ilia,

It is the default behaviour of the SearchPickerField: you set the search parameters, and the matches from optionsDatasource are displayed below the search field in a drop-down list. If you then open the lookup, it will be populated from its own datasource. The component’s optionsDatasource is not linked with the lookup screen’s datasource in any way.

If you want the lookup screen to display only filtered records too, you can override the lookup screen invocation method to set the parameters for its datasource query.

I appreciate your response but, to be honest, it’s not very clear to me… Which method am I supposed to override and how am I supposed to set a query for the datasource used within the lookup screen (I know the datasource can be refreshed with parameters, but I’d still need to include said parameters in the query)? The lookup screen is currently invoked by clicking on the SearchPickerField (default behaviour).

PickerField (and its inheritors) have some predefined standard actions. You can change the standard implementation of the LookupAction, for example, to set parameters for the lookup screen:

pickerField.getLookupAction().setLookupScreenParams(ParamsMap.of("customer", customersTable.getSingleSelected()));

I’ve made a sample project to show you how it works, please find attached. (30.7K)