Skip to main content
June 11, 2021
Question

Need to understand the Cascading of Drop down concept when data is from DB tables.

  • June 11, 2021
  • 4 replies
  • 0 views

Hi,
Could someone help me understand the concept and solve my below problem?

I have a Two tables

1. VehicleTypes
Field
Id   category
1    Cars
2    Buses
3   Trains

2nd table SubVehicleTypes

SubID Id SubCategory
1         1     Sedan
2         1     Suv
3         2     Luxury
4         2     Semi luxury
5         3     Ac Trains
6         3     Non Ac Trains


Requirements:
1. Drop Down 1 will have data from Table 1
2. Drop Down 2 will have data from Table 2

When I select category from DD1 the second DD2 should give Subcategory based on ID(Common in both Tables).

Thanks
Faisal

    4 replies

    June 11, 2021

    This is my Raw code

    a!localVariables(
    local!vehicleTypeData:rule!FF_Exp_VehiclesTypes(VehicleId:null),
    local!vehicleSubTypeData:rule!FF_Exp_VehiclesSubTypes(subId:null),
    local!vehicleType,
    local!vehicleSubType,
    {
    a!dropdownField(
    label: "Dropdown",
    labelPosition: "ABOVE",
    placeholder: "--- Select a Value ---",
    choiceLabels: local!vehicleTypeData.category,
    choiceValues: local!vehicleTypeData.id,
    saveInto: {},
    searchDisplay: "AUTO",
    validations: {}
    ),
    a!dropdownField(
    label: "Dropdown",
    labelPosition: "ABOVE",
    placeholder: "--- Select a Value ---",
    choiceLabels: local!vehicleSubType,
    choiceValues: local!vehicleSubType,
    saveInto: {},
    searchDisplay: "AUTO",
    validations: {}
    )
    })

    peter.lewis
    Employee
    June 11, 2021

    I'd suggest looking at the docs page for cascading dropdowns. Basically you will need to filter the results of your second list based on the selection from your first list, so you'll need a query that filters your sub-category by the category provided.

    acaciob0002
    June 13, 2021

    Hi Faisal,

    The code below is just a reference for help you to implement your final solution. It is a working code, but the values in the locals are map instead queries.  As Peter explained, you just need to replace the value in the local variables for your queries an use the selected vehicle id as a filter in the second query(subcategory).

    a!localVariables(
      local!selectedVehicleId,
      local!vehicle: 
        {
          a!map( id:1, value:"Cars" ),
          a!map( id:2, value: "Buses" ),
          a!map( id:3, value: "Trains"   )
      },  
      local!subCategory: {
        a!map( subTypeId:1, vehicleTypeId: 1, value: "Sedan" ),
        a!map( subTypeId:2, vehicleTypeId: 1, value: "Suv" ),
        a!map( subTypeId:3, vehicleTypeId: 2, value: "Luxury" ),
        a!map( subTypeId:4, vehicleTypeId: 2, value: "Semi Luxury" ),
        a!map(subTypeId:5, vehicleTypeId: 3, value: "Ac Trains" ),
        a!map( subTypeId:6, vehicleTypeId: 3, value: "Non Ac Trains" ),
      },  
      local!subType: if(
        isnull(local!selectedVehicleId),
        null,    
        index(local!subCategory,wherecontains(local!selectedVehicleId,tointeger(local!subCategory.vehicleTypeId)),null)
      ),
      local!selectedSubType,
      {    
        a!dropdownField(
          label: "Vehicle Type",
          labelPosition: "ABOVE",
          value: local!selectedVehicleId,
          placeholder: "Please select a vehicle",
          choiceLabels: local!vehicle.value,
          choiceValues: local!vehicle.id,
          saveInto: {
            a!save(local!selectedVehicleId,save!value),
            a!save(local!selectedSubType,null)
          }
        ),
        a!dropdownField(
          label: "Vehicle Sub Category",
          labelPosition: "ABOVE",
          value: local!selectedSubType,
          placeholder: "Please Vehicle Sub Category",
          choiceLabels: local!subType.value,
          choiceValues: local!subType.subTypeId,
          saveInto: {
            a!save(local!selectedSubType,save!value)
          }
        )
      }  
    )

    Hope it help you to achieve your goal,

    Cheers,

    Acacio B.

    June 15, 2021

    Hi Acacio,

    Thank you..I will follow what u and Peter have suggested.