How do I call upon a dependent dropdown field?

Hi all!

New to Appian, and I am stuck on figuring out how to correct configure a dependent dropdown. 

The first dropdown field is called "Plant," and its fields consist of plantId, value, & description. The second dropdown field is called "Storage Location," and its fields consist of werks, name1, & land1. Both queries have one similar field, which is "value" and "werks," but I need to call back "plantid." How would I do that?

Thanks! 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Use the selected plantId to lookup its corresponding value field from plantData, then filter storageData where werks matches that value to populate the dependent Storage Location dropdown.

    a!localVariables(
      /* Sample Plant Data */
      local!plantData: {
        a!map(plantId: 1, value: "P100", description: "Plant Chicago"),
        a!map(plantId: 2, value: "P200", description: "Plant Dallas"),
        a!map(plantId: 3, value: "P300", description: "Plant Boston")
      },
      /* Sample Storage Location Data */
      local!storageData: {
        a!map(werks: "P100", name1: "Warehouse A", land1: "USA"),
        a!map(werks: "P100", name1: "Warehouse B", land1: "USA"),
        a!map(werks: "P200", name1: "Storage Unit 1", land1: "USA"),
        a!map(werks: "P200", name1: "Storage Unit 2", land1: "USA"),
        a!map(werks: "P300", name1: "Depot North", land1: "USA"),
        a!map(werks: "P300", name1: "Depot South", land1: "USA")
      },
      /* Variables to store selections */
      local!selectedPlantId: null,
      local!selectedStorageLocation: null,
      /* Get the value field of selected plant */
      local!selectedPlantValue: if(
        a!isNullOrEmpty(local!selectedPlantId),
        null,
        index(
          local!plantData.value,
          wherecontains(local!selectedPlantId, local!plantData.plantId),
          null
        )
      ),
      /* Filter storage locations based on selected plant */
      local!filteredStorageLocations: if(
        a!isNullOrEmpty(local!selectedPlantValue),
        {},
        index(
          local!storageData,
          wherecontains(local!selectedPlantValue, local!storageData.werks),
          {}
        )
      ),
      /* Form Layout */
      a!formLayout(
        titleBar: "Plant and Storage Selection",
        contents: {
          /* Plant Dropdown */
          a!dropdownField(
            label: "Plant",
            placeholder: "-- Select Plant --",
            choiceLabels: local!plantData.description,
            choiceValues: local!plantData.plantId,
            value: local!selectedPlantId,
            saveInto: {
              local!selectedPlantId,
              a!save(local!selectedStorageLocation, null)
            },
            required: true
          ),
          /* Storage Location Dropdown - FIXED */
          a!dropdownField(
            label: "Storage Location",
            placeholder: "-- Select Storage Location --",
            disabled: a!isNullOrEmpty(local!selectedPlantId),
            choiceLabels: if(
              a!isNullOrEmpty(local!filteredStorageLocations),
              {},
              local!filteredStorageLocations.name1
            ),
            choiceValues: if(
              a!isNullOrEmpty(local!filteredStorageLocations),
              {},
              local!filteredStorageLocations.name1
            ),
            value: local!selectedStorageLocation,
            saveInto: local!selectedStorageLocation,
            required: true
          )
        }
      )
    )

Reply
  • 0
    Certified Lead Developer

    Use the selected plantId to lookup its corresponding value field from plantData, then filter storageData where werks matches that value to populate the dependent Storage Location dropdown.

    a!localVariables(
      /* Sample Plant Data */
      local!plantData: {
        a!map(plantId: 1, value: "P100", description: "Plant Chicago"),
        a!map(plantId: 2, value: "P200", description: "Plant Dallas"),
        a!map(plantId: 3, value: "P300", description: "Plant Boston")
      },
      /* Sample Storage Location Data */
      local!storageData: {
        a!map(werks: "P100", name1: "Warehouse A", land1: "USA"),
        a!map(werks: "P100", name1: "Warehouse B", land1: "USA"),
        a!map(werks: "P200", name1: "Storage Unit 1", land1: "USA"),
        a!map(werks: "P200", name1: "Storage Unit 2", land1: "USA"),
        a!map(werks: "P300", name1: "Depot North", land1: "USA"),
        a!map(werks: "P300", name1: "Depot South", land1: "USA")
      },
      /* Variables to store selections */
      local!selectedPlantId: null,
      local!selectedStorageLocation: null,
      /* Get the value field of selected plant */
      local!selectedPlantValue: if(
        a!isNullOrEmpty(local!selectedPlantId),
        null,
        index(
          local!plantData.value,
          wherecontains(local!selectedPlantId, local!plantData.plantId),
          null
        )
      ),
      /* Filter storage locations based on selected plant */
      local!filteredStorageLocations: if(
        a!isNullOrEmpty(local!selectedPlantValue),
        {},
        index(
          local!storageData,
          wherecontains(local!selectedPlantValue, local!storageData.werks),
          {}
        )
      ),
      /* Form Layout */
      a!formLayout(
        titleBar: "Plant and Storage Selection",
        contents: {
          /* Plant Dropdown */
          a!dropdownField(
            label: "Plant",
            placeholder: "-- Select Plant --",
            choiceLabels: local!plantData.description,
            choiceValues: local!plantData.plantId,
            value: local!selectedPlantId,
            saveInto: {
              local!selectedPlantId,
              a!save(local!selectedStorageLocation, null)
            },
            required: true
          ),
          /* Storage Location Dropdown - FIXED */
          a!dropdownField(
            label: "Storage Location",
            placeholder: "-- Select Storage Location --",
            disabled: a!isNullOrEmpty(local!selectedPlantId),
            choiceLabels: if(
              a!isNullOrEmpty(local!filteredStorageLocations),
              {},
              local!filteredStorageLocations.name1
            ),
            choiceValues: if(
              a!isNullOrEmpty(local!filteredStorageLocations),
              {},
              local!filteredStorageLocations.name1
            ),
            value: local!selectedStorageLocation,
            saveInto: local!selectedStorageLocation,
            required: true
          )
        }
      )
    )

Children
No Data