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

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

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

Children
No Data