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

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

  Discussion posts and replies are publicly visible

Parents
  • 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.

  • Hi Acacio,

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

Reply Children
No Data