Determining the different options of a pull-down menu from a database entity?

Certified Associate Developer

I am trying to populate the values of a pull-down menu from a database. For this purpose, I defined cons!GENERIC_TASKS which points to corresponding database entity. I also have the following expression rule which reads all necessary data from the respective entity:

a!queryEntity(
  entity: cons!GENERIC_TASKS,
  query: a!query(
    selection: a!querySelection(
      columns: {
        a!queryColumn(
          field: "genericTaskName"
        )
      }
    ),
    pagingInfo: a!pagingInfo(
      startIndex: 1,
      batchSize: -1
    )
  ),
  fetchTotalCount: false
)

The test result of this rule looks promising since it contains all required data, the labels and the values.

In my user interface, I am now trying the following:

    a!dropdownField(
      label: "Generic step type",
      labelPosition: "ABOVE",
      placeholder: "--- Please choose a step type ---",
      choiceLabels: {rule!APAS_GetAllGenericTaskNames.data.genericTaskName},
      choiceValues: {rule!APAS_GetAllGenericTaskNames.data.identifiers},
      saveInto: {},
      searchDisplay: "AUTO",
      validations: {}
    )

However, this gives me the following error:

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!dropdownField: Invalid index: Cannot index property 'data' of type Text into type Rule or Function Reference

What do I do wrong?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Why are you running the same query twice, once for choiceLabels and once for choiceValues?  That seems pretty inefficient.

    Instead you should be doing something like this, querying just once into a local variable and then referring to that subsequently.

    a!localVariables(
      local!taskNames: rule!APAS_GetAllGenericTaskNames().data,
      
      a!dropdownField(
        label: "Generic step type",
        labelPosition: "ABOVE",
        placeholder: "--- Please choose a step type ---",
        choiceLabels: local!taskNames.genericTaskName,
        choiceValues: local!taskNames.identifiers,
        saveInto: {},
        searchDisplay: "AUTO",
        validations: {}
      )
    )

    As an aside: you've posted code a few different ways above, but I universally recommend using the "Code Box" i've used here.  For reference:

Reply
  • 0
    Certified Lead Developer

    Why are you running the same query twice, once for choiceLabels and once for choiceValues?  That seems pretty inefficient.

    Instead you should be doing something like this, querying just once into a local variable and then referring to that subsequently.

    a!localVariables(
      local!taskNames: rule!APAS_GetAllGenericTaskNames().data,
      
      a!dropdownField(
        label: "Generic step type",
        labelPosition: "ABOVE",
        placeholder: "--- Please choose a step type ---",
        choiceLabels: local!taskNames.genericTaskName,
        choiceValues: local!taskNames.identifiers,
        saveInto: {},
        searchDisplay: "AUTO",
        validations: {}
      )
    )

    As an aside: you've posted code a few different ways above, but I universally recommend using the "Code Box" i've used here.  For reference:

Children
No Data