How to display data dynamically based on previous selected data

A Score Level 1

Hi,

I have two dropdowns in my interface. Based on first selected dropdown second dropdown has to chaange.

like, First dropdown is 'Country' . If i select the country it should display list of states for that country.

I have created multiple constants for states for each and every country.

My constants are 

APPNAME_COUNTRY - List of countries

APPNAME_COUNTRYNAME1 - list of states for that country

APPNAME_COUNTRYNAME2 - List of states for countryname2

So if i select country i have to populate another dropdown (states) in Interface. So how can i call the constants dynamically. Below is the validation i tried but no luck. Please help.

if (
isnull(ri!APPNAME_Customer_Details.address.country),
null,
cons!BP_+upper(ri!APPNAME_Customer_Details.address.country)
)

Regards,

Sirisha

Regards,

Sirisha

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Senior Developer
    in reply to sirid

    In this case, you have to maintain States constant for each country. Based on selected country, you have to map the corresponding States constant to the variable of choiceLabels/ChoiceValues in Country dropdown SaveInto

    I suggest you to go for a table option if you are having many Countries

  • 0
    A Score Level 2
    in reply to sirid

    Yes agree,
    Its possible with 2 but because you have a trimmed down second dropDown it will be though to do.

    If its only 2 you can have

    1 constant with countires
    1 with states

    STATE_CONSTANT[value of country constant]

  • 0
    Certified Senior Developer
    in reply to Timo

    Please check the example

    load(
      local!countryLabelConstant:{"IND","USA","UK"},
      local!countryValuesConstant:{1,2,3},
      local!indStatesConstant:{"TN","AP"},
      local!usaStatesConstant:{"AL","AK"},
      local!ukStatesConstant:{"JK","JL"},
      local!states,
      local!selectedCountry,
      local!selectedState,
      {
        a!dropdownField(
          label: "Country",
          placeholderLabel: "Please select",
          choiceLabels: local!countryLabelConstant,
          choiceValues: local!countryValuesConstant,
          value: local!selectedCountry,
          saveInto: {
            local!selectedCountry,
            a!save(
              local!selectedState,
              NULL
            ),
            a!save(
              local!states,
              choose(
                save!value,
                local!indStatesConstant,
                local!usaStatesConstant,
                local!ukStatesConstant
              )
            )
          }
        ),
        a!dropdownField(
          showWhen: not(
            rule!APN_isBlank(
              local!selectedCountry
            )
          ),
          label: "States",
          placeholderLabel: "Please select",
          choiceLabels: local!states,
          choiceValues: local!states,
          value: local!selectedState,
          saveInto: local!selectedState
        )
      }
    )