<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Cascading Dropdown to 3 levels</title><link>https://community.appian.com/discussions/f/user-interface/18398/cascading-dropdown-to-3-levels</link><description>I am trying to implement 3 level cascading dropdown fields. &amp;#39;State&amp;#39; dropdown field will have choices based on &amp;#39;country&amp;#39; selected and &amp;#39;City&amp;#39; dropdown field will have choices based on &amp;#39;State&amp;#39; selected. I have created choices for &amp;#39;States&amp;#39; field using choose</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Cascading Dropdown to 3 levels</title><link>https://community.appian.com/thread/72432?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 14:17:07 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2d8d484b-4f10-4dd1-a19d-812c4cb5a662</guid><dc:creator>Stewart Burchell</dc:creator><description>&lt;p&gt;Hi Sudip&lt;/p&gt;
&lt;p&gt;The key to this is the data model. You want to create data sets that can be related. There will be three sets of data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Countries, with a key and a name e.g. &amp;#39;1&amp;#39; and &amp;#39;USA&amp;#39;&lt;/li&gt;
&lt;li&gt;States, with a key, a foreign key relating the State to a Country, and a name e.g. &amp;#39;1&amp;#39;, &amp;#39;1&amp;#39;, &amp;#39;Colorado&amp;#39;&lt;/li&gt;
&lt;li&gt;Cities, with a key, and a foreign key relating the City to the State, and a name e.g. &amp;#39;1&amp;#39;, &amp;#39;1&amp;#39;, &amp;#39;Denver&amp;#39;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here&amp;#39;s an example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!countries: {
    {countryId: 1, countryName: &amp;quot;Australia&amp;quot;},
    {countryId: 2, countryName: &amp;quot;United States of America&amp;quot;}
  },
  local!states: {
    /* States of Australia */
    {stateId: 1, countryId: 1, stateName: &amp;quot;New South Wales&amp;quot;},
    {stateId: 2, countryId: 1, stateName: &amp;quot;Queensland&amp;quot;},
    /* States of USA */
    {stateId: 11, countryId: 2, stateName: &amp;quot;Alabama&amp;quot;},
    {stateId: 12, countryId: 2, stateName: &amp;quot;Alaska&amp;quot;},
    {stateId: 13, countryId: 2, stateName: &amp;quot;Arkansas&amp;quot;},
    {stateId: 14, countryId: 2, stateName: &amp;quot;California&amp;quot;},
    {stateId: 15, countryId: 2, stateName: &amp;quot;Colorado&amp;quot;}
  },
  local!cities: {
    /* Cities of New South Wales, Australia */
    {cityId: 1, stateId: 1, cityName: &amp;quot;Sydney&amp;quot;},
    {cityId: 2, stateId: 1, cityName: &amp;quot;Wollongong&amp;quot;},
    /* Cities of Colorado, USA */
    {cityId: 12, stateId: 15, cityName: &amp;quot;Boulder&amp;quot;},
    {cityId: 13, stateId: 15, cityName: &amp;quot;Denver&amp;quot;}
  },
  local!selectedCountry: null,
  local!selectedState: null,
  local!selectedCity: null,
  {
    a!dropdownField(
      label: &amp;quot;Countries&amp;quot;,
      placeholderLabel: &amp;quot;---Select a Country---&amp;quot;,
      choiceLabels: fn!index(local!countries,&amp;quot;countryName&amp;quot;, null),
      choiceValues: fn!index(local!countries,&amp;quot;countryId&amp;quot;,null),
      value: local!selectedCountry,
      saveInto: {
        local!selectedCountry,
        a!save(
          {local!selectedState,local!selectedCity},
          null
        )
      }
    ),
    a!dropdownField(
      showWhen: fn!not(fn!isnull(local!selectedCountry)),
      label: concat(
        &amp;quot;States for &amp;quot;,
        local!countries.countryName[
          wherecontains(
            local!selectedCountry,fn!tointeger(local!countries.countryId))
        ]
      ),
      placeholderLabel: &amp;quot;---Select a State ---&amp;quot;,
      choiceLabels: local!states.stateName[wherecontains(local!selectedCountry,tointeger(local!states.countryId))],
      choiceValues: local!states.stateId[wherecontains(local!selectedCountry,tointeger(local!states.countryId))],
      value: local!selectedState,
      saveInto: {
        local!selectedState,
        a!save(
          local!selectedCity,
          null
        )
      }
    ),
    a!dropdownField(
      showWhen: fn!not(fn!isnull(local!selectedState)),
      label: concat(
        &amp;quot;Cities for &amp;quot;,
        local!states.stateName[
          wherecontains(
            local!selectedState,fn!tointeger(local!states.stateId))
        ]
      ),
      placeholderLabel: &amp;quot;---Select a City ---&amp;quot;,
      choiceLabels: local!cities.cityName[wherecontains(local!selectedState, tointeger(local!cities.stateId))],
      choiceValues: local!cities.cityId[wherecontains(local!selectedState, tointeger(local!cities.stateId))],
      value: local!selectedCity,
      saveInto: {
        local!selectedCity
      }
    )
  }
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cascading Dropdown to 3 levels</title><link>https://community.appian.com/thread/72431?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 14:02:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:04cac225-0839-4584-ad01-840fea8ad1db</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;I have to agree with Mike quite strongly on the limitations of the choose function here.&amp;nbsp; The difficulty is that with choose, you have to know beforehand how many options you will have, and always have to have exactly that many options, or you invite aberrant behavior at the very best.&lt;/p&gt;
&lt;p&gt;The goal is to make&amp;nbsp;choiceLabels and choiceValues.&amp;nbsp; You could create a helper rule that just outputs a list of cities given a state input.&amp;nbsp; That could actually run on a simple choose function, but return lists of Text.&amp;nbsp; That gets you labels.&amp;nbsp; Then call the same rule, but a!forEach(items: rule!yourHelperRule(ri!state), expression: fv!index) to get the choiceValues.&amp;nbsp; Maybe that would work?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cascading Dropdown to 3 levels</title><link>https://community.appian.com/thread/72429?ContentTypeID=1</link><pubDate>Tue, 03 Mar 2020 13:47:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5a26dab5-2a69-41b5-b101-f689d3029861</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;How you do this largely depends on where and how you&amp;#39;re sourcing your state / city data.&amp;nbsp; Are you querying them from a DB on demand?&amp;nbsp; Or all up front?&amp;nbsp; Or getting them from somewhere else?&lt;/p&gt;
&lt;p&gt;As a personal preference I typically avoid the choose() function as it has particular drawbacks that hinder its use (like the near impossibility of specifying a safe/default condition without bending over backwards).&amp;nbsp; But I can&amp;#39;t tell what to recommend you should try without seeing perhaps some sample code.&lt;/p&gt;
&lt;p&gt;If you could post either your interface code or a representative example here that&amp;nbsp; would help (please use the &amp;quot;Insert --&amp;gt; Insert Code&amp;quot; tool to create a code box which will retain formatting and indentation, as well as preventing the thread from becoming impossible to read).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>