Skip to main content
shubhamk0004
September 19, 2022
Question

Select countries based on Regions

  • September 19, 2022
  • 3 replies
  • 0 views

Hi folks,

New to Appian!

I need to create an interface which will allow a user to select/unselect the countries based on regions.

Description:

1. An Interface is having 2 dropdown lists first Region List and second is Countries list. (created)

2. All countries belongs to selected region must be selected automatically whenever an user selects a region.

3. An user can unselect one or more country(s) from the countries list if he wants.

Looking for a detailed suggestion or solution to implement this functionality.

Thank you in advance!

Regards,

Shubham Kumar

3 replies

harshitb6843
September 19, 2022

This code snippet should help

a!localVariables(
  local!regions: {
    { id: 1, name: "Region 1",  },
    { id: 2, name: "Region 2",  },
    { id: 3, name: "Region 3",  }
  },
  local!countries: {
    { id: 1, name: "Country 1", regionId: 1 },
    { id: 2, name: "Country 2", regionId: 1 },
    { id: 3, name: "Country 3", regionId: 1 },
    { id: 4, name: "Country 4", regionId: 2 },
    { id: 5, name: "Country 5", regionId: 2 },
    { id: 6, name: "Country 6", regionId: 2 }
  },
  local!selectedRegion,
  local!selectedCountries,
  {
    a!multipleDropdownField(
      label: "Region",
      choiceLabels: local!regions.name,
      choiceValues: local!regions.id,
      value: local!selectedRegion,
      saveInto: {
        local!selectedRegion,
        a!save(
          local!selectedCountries,
          a!flatten(
            index(
              local!countries.id,
              wherecontains(
                tointeger(local!selectedRegion),
                tointeger(local!countries.regionId)
              ),
              {}
            )
          )
        )
      },
      placeholder: "---Country---"
    ),
    a!multipleDropdownField(
      label: "Country",
      choiceLabels: a!flatten(
        index(
          local!countries.name,
          wherecontains(
            tointeger(local!selectedRegion),
            tointeger(local!countries.regionId)
          ),
          {}
        )
      ),
      choiceValues: a!flatten(
        index(
          local!countries.id,
          wherecontains(
            tointeger(local!selectedRegion),
            tointeger(local!countries.regionId)
          ),
          {}
        )
      ),
      value: local!selectedCountries,
      saveInto: local!selectedCountries,
      placeholder: "---Country---"
    )
  }
)

shubhamk0004
September 19, 2022

Hi Harshit,

Thanks for your quick reply!

User can select multiple regions at a time, and countries belongs to regions must be auto selected in countries dropdwon list

harshitb6843
September 19, 2022

I have updated the code. Let me know if it works.