Example 4: Configure dependent custom fields
These examples explore different approaches to configuring dependent custom fields with Power Custom Fields (PCF).
Example 1
This example demonstrates how to configure Power Custom Fields to use dependent fields to display continent and country selection:
Primary field: PCF - Single Autocomplete (continents)
Dependent field: PCF - Multiple Autocomplete (countries)
The configuration uses SIL Data Source.
The primary field contains five continent options. The dependent field dynamically displays countries filtered from the database countries table based on the selected continent.
To establish this dependency:
In the Data Source section of the country field's configuration (PCF - Multiple Autocomplete), add the continent field (PCF - Single Autocomplete) as a dependent field.
The country field then uses the continent field's value to filter the displayed countries.
The Dependent fields setting is available only for Power custom fields of the following type:
PCF - Single Select
PCF - Single Autocomplete
PCF - Multi Select
PCF - Multiple Autocomplete
Configure the data source scripts.
The following SIL data source script populates the continent field (PCF - Single Autocomplete):
return {"AFRICA", "ASIA", "EUROPE", "AMERICA", "OCEANIA"};The following SQL data source script filters countries for the dependent field based on the selected continent:
string x = argv["customfield_10208"];
string[] res = sql("myDB", "select country from countries where continent like '" + x + "'");
return res;
The fields appear on the view issue screen as shown in the screenshot below:
Example 2
This example demonstrates how to use PCF to create dynamic dependent fields where the dependent field values are computed from the primary field selection:
Primary field: PCF - Single Autocomplete (countries)
Dependent field: PCF - Single Autocomplete (letters)
The configuration uses SIL Data Source.
The primary field displays a list of countries. When a country is selected, the dependent field dynamically generates a list of letters from that country's name.
To establish this dependency:
In the Data Source section of the letters field's configuration (PCF - Single Autocomplete), add the country field as a dependent field
The letters field then extracts individual letters from the selected country name
The following SIL data source script populates the country field (primary field):"
return {"Romania", "France", "Norway", "Spain"};The following SIL data source script generates letters for the dependent field based on the selected country:
string[] letters = {};
string cfname="Country";
for(int i=0; i<length(argv[cfname]); ++i) {
letters += argv[cfname][i];
}
return letters;When a country is selected, the dependent field displays all letters from that country's name.
Example 3
This example demonstrates how to use PCF to create dependent fields using SQL data sources:
Primary field: PCF - Single Autocomplete (Continent)
Dependent field: PCF - Multiple Autocomplete (Countries)
The configuration uses a database table 'countries' with two columns: country and continent. The primary field displays unique continent values, while the dependent field shows countries filtered by the selected continent.
To establish this dependency:
In the Data Source section of the Countries field configuration, add the Continent field as a dependent field.
Configure both fields to use SQL data sources:
For the PCF - Single Autocomplete (Continent) field, use this SQL Initial Script:
select distinct continent from countries;For the PCF - Multiple Autocomplete (Countries) field, use this SQL script for both Initial Script and Autocomplete Script:
select country from countries where continent = {customfield_10800}The fields appear on the view issue screen as shown below:
Need support? Create a request with our support team.
Copyright © 2005 - 2026 Appfire | All rights reserved.
