Skip to main content
December 30, 2023
Question

Dependent drop down not working dynamically

  • December 30, 2023
  • 3 replies
  • 0 views

Hi All,

As part of practice and POC purpose. There was requirement like i have created three drop down fields on UI and also there are also Three tables created DB(Tables- States, Cities, Towns).

Sates- drop down and City-Drop down working as expected based on selected state value cities were displaying but based on selected City value towns drop down field values not showing up.

null parameter was passing when i checked local variables. i tried different ways but not able to achieve this.

could you please help on this.  

below code for reference

a!localVariables(
local!stateData: rule!KT_getStateDataById(),
local!stateName: property(local!stateData, "state",null),
local!stateId: property(local!stateData,"id",null),
local!cityname: rule!KT_getCityByStateId(stateId:ri!stateid ),

 local!townname: rule!KT_getTownNameByCityId(cityid: ri!cityId),

{
a!sectionLayout(
label: "",
contents: {
a!columnsLayout(
columns: {
a!columnLayout(
contents: {
a!dropdownField(
choiceLabels: local!stateName,
choiceValues: local!stateId,
label: "States",
labelPosition: "ABOVE",
placeholder: "--- Select a Value ---",
value: ri!stateid,
saveInto: {
ri!stateid,
a!save(ri!cityName,null)
},
searchDisplay: "AUTO",
validations: {}
)
}
),
a!columnLayout(
contents: {
a!dropdownField(
choiceLabels: local!cityname,
choiceValues: local!cityname,
label: "Cities",
labelPosition: "ABOVE",
placeholder: "--- Select a Value ---",
value: ri!cityName,
saveInto: {
ri!cityName,

},
searchDisplay: "AUTO",
validations: {}
)
}
),
a!columnLayout(
contents: {
a!dropdownField(
choiceLabels: local!towname,
choiceValues: local!towname,
label: "Towns",
labelPosition: "ABOVE",
placeholder: "--- Select a Value ---",
value: ri!townName,
saveInto: {ri!townName},
searchDisplay: "AUTO",
validations: {}
)
}
)
}
)
}
)

3 replies

December 30, 2023

Hi Kishore,
In the second drop-down, "Cities", you are saving the 'city name'. However, in the query rule to retrieve the town name, you are passing the 'city ID' instead of the selected city name. 

I recommend indexing city names and city IDs in a manner similar to how you indexed state names and state IDs. Utilize the indexed city names and city IDs for drop-down choice labels and values, respectively. Save the city ID instead of the city name to populate the town names.

December 31, 2023

Hi Mathurambika,

Thanks for reply. so, you meant again i need to write one more rule for City entity to fetch data right instead of passing value like what i a had written for State entity?

December 31, 2023

Yes, you can do the following:

  1. Either, query the city data(not all the columns, use query selection), index the city name and ID, and use them in the dropdown (OR)
  2. Create a rule to query the town name based on the selected city name.