Skip to main content
iswaryan3555
April 14, 2025
Question

Displaying unique value in dropdown

  • April 14, 2025
  • 10 replies
  • 0 views

I have 2 dropdowns type and courses type will be premium, free and courses for premium java, c++, and also for free also I have java , python like this . i need to display all the courses when in default and when type selected as premium it will only show that category courses. but java is in both category it displaying 2 times by default . In db they have mapped with thier unique type ids only. I tried with union but choice values and choice values length varies because of that. Can anyone help me ?

10 replies

stefanhelzle0001
April 14, 2025

Would it be possible to create two dropdowns for courses, and show one of them depending on the type?

iswaryan3555
April 14, 2025

Are you are saying like one dropdown named courses for premium, other one is courses for free. I am not sure we can do like that. 

stefanhelzle0001
April 14, 2025

That's the idea. Using showWhen, you can hide/display the second dropDown based on the selected type.

April 14, 2025

When I read "unique" my first thought is the union() function.  I'm not sure where you're dropdown values come from or how your objects are configured, but you could try something like below...

a!localVariables(
  
  local!selectedType,
  local!selectedCourse,
  local!dropdownOptionsMap: {
    a!map(course: "Java", type: "Premium"),
    a!map(course: "C++", type: "Premium"),
    a!map(course: "Appian", type: "Premium"),
    a!map(course: "Java", type: "Free"),
    a!map(course: "Python", type: "Free"),
    a!map(course: "Javascript", type: "Free"),
  },
  
  local!allCourseOptions: union(local!dropdownOptionsMap.course,local!dropdownOptionsMap.course),
  
  local!courseOptions: if(
    a!isNotNullOrEmpty(local!selectedType),
    index(local!dropdownOptionsMap, wherecontains(local!selectedType, local!dropdownOptionsMap.type)).course,
    local!allCourseOptions
  ),
  
  
  {
    a!dropdownField(
      label: "Course Type",
      placeholder: "Select Course Type",
      choiceLabels: union(local!dropdownOptionsMap.type,local!dropdownOptionsMap.type),
      choiceValues: union(local!dropdownOptionsMap.type,local!dropdownOptionsMap.type),
      value: local!selectedType,
      saveInto: {
        local!selectedType,
        a!save(local!selectedCourse, null)
      }
    ),
    a!dropdownField(
      label: "Course",
      placeholder: "Select Course",
      choiceLabels: local!courseOptions,
      choiceValues: local!courseOptions,
      value: local!selectedCourse,
      saveInto: {
        local!selectedCourse,
        a!save(
          local!selectedType,
          if(
            and(
              a!isNotNullOrEmpty(save!value),
              length(
                index(
                  local!dropdownOptionsMap,
                  wherecontains(
                    save!value,
                    local!dropdownOptionsMap.course
                  )
                ).type
              ) = 1
            ),
            index(
              local!dropdownOptionsMap,
              wherecontains(
                save!value,
                local!dropdownOptionsMap.course
              )
            ).type,
            null
          )
        )
      }
    )
  }
)

The list of course options begins with all unique values in the local!dropdownOptionsMap.course.  Notice Java is listed twice in local!dropdownOptionsMap.course.  To get the unique list I just used union(local!dropdownOptionsMap.course, local!dropdownOptionsMap.course).

Added some logic in course selection to set the type if the selected course is unique in the list of options and logic in the type selection to clear away any previously selected course.

Hope this helps!

iswaryan3555
April 15, 2025

Will try this.Thanks.

tejak2639
April 15, 2025

As per my understanding on what you said. You are having a table that contains the courses like this 
CourseId  Course     Type
1               Java         Premium

2               Java         Free

So from this table only you are going to get the courses and displaying them in drop-down right?
You are trying union on courses that is choice labels and unable to use union on choice values that is courseId.
If this is the case I have some doubts

1.Why you want to show all the courses in drop-down before selecting type?

2.What you want to store as type premium or free when no type is selected and you are selecting the course?

If no type is selected and if you want to store free then you can have the choice values {2} instead of {1,2} by using wherecontains and index.

April 15, 2025

Hi [mention:24ecc13e300c47b1a73ada75867e8d92:e9ed411860ed4f2ba0265705b8793d05] 

a!dropdownField should have unique choice values, I would suggest you to show the course type first and then showing courses based on the selected course type or else you can also use a!dropdownFieldByIndex

Refer to : https://docs.appian.com/suite/help/24.2/Dropdown_By_Index_Component.html

mikes0011
Brainy
April 15, 2025

If both "java" entries have single, unique type IDs, does that imply that the two different "Java" offerings are actually different (as in, it sounds like there are 2 separate entries in your DB)?  In that case maybe you should consider changing the label for one of them to be distinct, like "Java (premium)", etc.