Conditional Dropdown

Hello Experts,

I have a requirement where user need to select multiple values for OrderType. There are different sets of values which needs to be populated under SearchBy on the selection of order type.

If Multiple Values are selected under the OrderType then only those values should be available under the SearchBy which are common to both.

Example 1: Lets say for OrderType "O1" SearchBy can be {"S1","S2","S3"} and  for OrderType "O2" SearchBy can be {"S1","S2","S3","S4","S5"}, So if user selects both the orders O1 and O2 then only {"S1","S2","S3"} should be available as SerachBy as common of two order types

Example 2: Lets say for OrderType "O1" SearchBy can be {"S1","S2","S3"} and  for OrderType "O2" SearchBy can be {"S1","S2","S3","S4","S5"} and for OrderType "O3" SearchBy can be {"S2"} So if user selects all the orders O1,O2 and O3 then only {"S2"} should be available as SerachBy as common of two order types.

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Here you can create a table in the DB and on the basis of each selection you can query the data and use intersection function to get the expected result.

  • 0
    Certified Lead Developer

    Hi Gaurav, Check the code below

    a!localVariables(
      local!orders: { "o1", "o2", "o3" },
      local!orderType: {
        a!map(orderType: "o1", value: "s1"),
        a!map(orderType: "o1", value: "s2"),
        a!map(orderType: "o1", value: "s3"),
        a!map(orderType: "o2", value: "s1"),
        a!map(orderType: "o2", value: "s2"),
        a!map(orderType: "o3", value: "s5"),
        a!map(orderType: "o3", value: "s4"),
        
      },
      local!selectedValues,
      local!allSelectedValues: a!flatten(
        a!forEach(
          items: local!selectedValues,
          expression: index(
            local!orderType,
            wherecontains(
              fv!item,
              index(local!orderType, "orderType", {})
            ),
            "value",
            {}
          )
        )
      ),
      local!unionSelectedValues: union(
        local!allSelectedValues,
        local!allSelectedValues
      ),
      local!fetchingDuplicates: reject(
        fn!isnull,
        a!forEach(
          items: local!unionSelectedValues,
          expression: if(
            count(
              wherecontains(fv!item, local!allSelectedValues)
            ) = length(local!selectedValues),
            /* In case you need to have duplicate values which are even present in two of the selected values change the condition to local!selectedValues - 1*/
            fv!item,
            null
          )
        )
      ),
      {
        a!multipleDropdownField(
          label: "Select Order",
          placeholder: "Select Order",
          choiceLabels: local!orders,
          choiceValues: local!orders,
          value: local!selectedValues,
          saveInto: local!selectedValues
        ),
        a!richTextDisplayField(
          value: if(
            count(local!fetchingDuplicates),
            local!fetchingDuplicates,
            "No Values found which belongs to all selected values",
            
          )
        )
      }
    )

  • 0
    Certified Senior Developer

    Hello GauravSingh,

    The below code will work if your requirement is exactly as mentioned in your question. But you might have to try a different method incase you want to add more dropdown options in the multiple dropdown field.

    a!localVariables(
      local!selectby,
      local!ordertype,
      local!options1:{"S1","S2","S3"},
      local!options2:{"S1","S2","S3","S4","S5"},
      local!options3: intersection({"S1","S2","S3"},{"S1","S2","S3","S4","S5"}),
      local!options4:{"S2"},
      local!dropdowncondition:{
        if(
          local!ordertype="O1",local!options1,if(
            local!ordertype="O2",local!options2,if(
              local!ordertype="O2; O1",local!options3,if(
                local!ordertype="O3",local!options4,if(
                 local!ordertype="O1; O2",local!options3,local!options4
                )
              )
            )
          )
        )
      },
      {
        a!multipleDropdownField(
          label: "Order Type",
          placeholder: "select",
          choiceLabels: {"O1","O2","O3"},
          choiceValues: {"O1","O2","O3"},
          saveInto: local!ordertype,
          value: local!ordertype
        ),
        a!dropdownField(
          label: "Search By",
          placeholder: "Select",
          choiceLabels: local!dropdowncondition,
          choiceValues: local!dropdowncondition,
          value: local!selectby,
          saveInto: local!selectby,
        )
      }
      
    )