Skip to main content
Known Participant
November 8, 2022
Solved

Dependent dropdown choose stores the ID in the database instead of the value that i picked

  • November 8, 2022
  • 4 replies
  • 4 views
When I submit a form with a dependent dropdown fields, it stores the ID in the database...
I want to store the value or text that I chose...
HOW I DO THAT?
please help
Best answer by peter.lewis

Are you sure you want to store the text though? In general storing the ID will better support changes in the future - for instance, if you update the value, all the places that reference the ID will now immediately receive the new value. Plus, it's easier to do things like define relationships or reporting if you have more consistent data that references an ID.

4 replies

Participating Frequently
November 8, 2022

You have to simply take the variable as text and pass the choice values as text which you are using in labels.

a!localVariables(
  local!selectedDepartment,
  local!labels: {
    "Corporate",
    "Engineering",
    "Finance",
    "Human Resources",
    "Professional Services",
    "Sales"
  },
  a!sectionLayout(
    label: "Example: Cascading Dropdowns",
    contents: {
      a!dropdownField(
        label: "Department",
        choiceLabels: local!labels,
        choiceValues: local!labels,
        /*pass same as labels of whatever you want to store*/
        placeholder: "-- Select a Department -- ",
        value: local!selectedDepartment,
        saveInto: { local!selectedDepartment,  }
      ),
      
    }
  )
)

danna3499Author
Known Participant
November 8, 2022

thanks Ujjwal. it works 

peter.lewis
Employee
November 8, 2022

Are you sure you want to store the text though? In general storing the ID will better support changes in the future - for instance, if you update the value, all the places that reference the ID will now immediately receive the new value. Plus, it's easier to do things like define relationships or reporting if you have more consistent data that references an ID.

danna3499Author
Known Participant
November 8, 2022

It's true, I don't think about that