Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Button handy
blanktrue
color#0052CC
nameSend Feedback
linkhttps://docs.google.com/forms/d/e/1FAIpQLScmToBe3vynAlb5fdKwCGxYqnTbDc66sIBgeecG2BuFDuHc7g/viewform?entry.2002826954=Example+1+-+Working+with+large+data+sets+-+15481685
widthauto

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: 

image-20240214-161133.png

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.

Code Block
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: 

image-20240214-163329.png

We can use a select script to do specific things when an item from the autocompleted list is selected:  

Code Block
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

Child pages (Children Display)
pageExamples for PCF