Example 1 - Working with large data sets
For this example, you have a business selling car parts. You have thousands of products and work with large data sets. Power Custom Fields helps save you time by no longer requiring you to go through the list of all products to select the necessary one.
The app lets you intervene in the data build-up process, including the autocomplete stages. You can see this in the following image:
For this example, we have a PCF - Single Autocomplete custom field configured in the follow ways:
One SIL Data Source
One script file
Minimum characters for autocomplete is set to 5
The maximum results number set to 50 and the filtering strategy set to "DATASOURCE."
We want to select from our big data set the items using the ids they have.
We used the following SIL data source.
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;
In the script above:
myDB represents the resource name of the data base used.
car_parts represent the table from the data base we want to select from.
("name", "id") are the columns converted to an object of the KPOption type and represented by a pair (label, value).
If you use this script as data source, your custom field will be populated like this:
We can use a select script to do specific things when an item from the autocompleted list is selected:
KPOption[] selectedOptions = customfield_12101;
description += "You have selected the next item: " + selectedOptions[size(selectedOptions)-1].label +
"; " + selectedOptions[size(selectedOptions)-1].value + "\n ";
The example above sets the description like this:
See More