Example 1: Use PCF autocomplete for large data sets
This example demonstrates Power Custom Fields (PCF) implementation for an auto parts inventory system with 1000+ products. The app's autocomplete functionality eliminates the need to scroll through complete product lists for selection.
The data build-up process can be customized at multiple stages, including autocomplete configuration, as illustrated below:
This example uses a PCF - Single Autocomplete custom field configuration using the following parameters:
One data source of type: SIL Data Source
Single script file
Minimum characters for autocomplete: 5
Maximum results: 50
Filtering strategy: Data source
This configuration enables item selection from large datasets using specific IDs through the following SIL data source script:
string s = argv["query"];
KPOption [] res;
if(length(s) > 2) {
KPOption[] options = sql("myDB", "select name, id from car_parts where id like '%" + s + "%' limit 100" );
for (int r = 0; r < size(options); r++) {
if (contains(options[r].value, s)) {
res = addElementIfNotExist(res, options[r]);
}
}
}
return res;
The components used in this script are:
myDB
: Resource name of the target databasecar_parts
: Source table in the databasename
,id
: Database columns that convert to KPOption type objects, wherename
becomes the label andid
becomes the value
The resulting autocomplete field appears as shown below:
A select script can be added to perform specific actions when a user selects an item from the autocomplete list. The following script example updates the description field with the selected item's details:
KPOption[] selectedOptions = customfield_12101;
description += "You have selected the next item: " + selectedOptions[size(selectedOptions)-1].label +
"; " + selectedOptions[size(selectedOptions)-1].value + "\n ";
The script modifies the description field to display as shown in the following image with specific options selected:
Related content
Need support? Create a request with our support team.
Copyright © 2005 - 2025 Appfire | All rights reserved.