Select countries based on Regions

Certified Associate Developer

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

  Discussion posts and replies are publicly visible

  • 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---"
        )
      }
    )

  • 0
    Certified Associate Developer
    in reply to Harshit Bumb (Appyzie)

    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

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