Activities
latest
false
Banner background image
Workflow Activities
Last updated Apr 22, 2024

Conditional Dropdowns

Conditional dropdowns enable you to select an option from the dropdown, based on a previous selection made in another form component.

For example, if you select a specific state from a dropdown list, the conditioned dropdown displays the cities in that state.

Tutorial

To use this feature:

  1. Create a parent dropdown, by defining a workflow variable of type List<String> or Dictionary<String, String>. For example, stateList.
  2. Create a child dropdown, by defining a workflow variable of type Dictionary<String, List<String>> or Dictionary<String, Dictionary<String, String>>. For example, cityStateMap.


  3. Drag and drop the Invoke Code activity into the workflow sequence.
  4. Click Edit Arguments and add the previously created variables as In/Out arguments. Click OK.



  5. Click Edit Code. Enter the code to initialize the data and populate the dropdowns with data. For example, the following code snippet initializes the dropdowns (stateList and cityStateMap) and adds items to them.
    // initialize the parent dropdown
    stateList = new List<string>();
    // add items to the parent dropdown
    stateList.Add("HP");
    stateList.Add("Punjab");
    // initialize the child dropdown
    cityStateMap = new Dictionary<string,List<string>>();
    // add items to the HP-child dropdown
    cityStateMap.Add("HP",new List<string>());
    cityStateMap["HP"].Add("Shimla");
    cityStateMap["HP"].Add("Solan");
    cityStateMap["HP"].Add("Hamirpur");
    // add items to the Punjab-child dropdown
    cityStateMap.Add("Punjab", new List<string>());
    cityStateMap["Punjab"].Add("Chandigarh");
    cityStateMap["Punjab"].Add("Patiala");
    cityStateMap["Punjab"].Add("Jalandhar");// initialize the parent dropdown
    stateList = new List<string>();
    // add items to the parent dropdown
    stateList.Add("HP");
    stateList.Add("Punjab");
    // initialize the child dropdown
    cityStateMap = new Dictionary<string,List<string>>();
    // add items to the HP-child dropdown
    cityStateMap.Add("HP",new List<string>());
    cityStateMap["HP"].Add("Shimla");
    cityStateMap["HP"].Add("Solan");
    cityStateMap["HP"].Add("Hamirpur");
    // add items to the Punjab-child dropdown
    cityStateMap.Add("Punjab", new List<string>());
    cityStateMap["Punjab"].Add("Chandigarh");
    cityStateMap["Punjab"].Add("Patiala");
    cityStateMap["Punjab"].Add("Jalandhar");
  6. Drag and drop the Create Form activity.
  7. Store the user dropdown selection into workflow variables. For example:

    • cityListSelected, of type List<String>—stores the list corresponding to the selected state.
    • selectedState, of type String—stores the selected state.
    • selectedCity, of type String—stores the selected city.
  8. Open the FormFieldsCollection window from the activity Properties panel.
  9. To define the dropdown fields in the form:

    • Define the dropdown fields. The Name you set is used for data binding (see Dropdown Component > Field Key tab > Property name).
    • Additionally, define the dropdown lists by appending _dropdown to the dropdown field name.
  10. In the Value column, set the user selection as follows:

    • For the parent dropdown list, use the list defined at Step 1.
    • For the child dropdown list, use the variable stored at Step 7.
    • For the parent dropdown field, use the variable stored at Step 7.
    • For the child dropdown field, use the variable stored at Step 7.



  11. Click OK.

Sample Workflow

To check the complete workflow or to have a future reference, download the XAML example

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.