Skip to main content
October 10, 2024
Question

Custom Picker selection incorrectly populating field

  • October 10, 2024
  • 5 replies
  • 0 views

Hello,

I'm working with a custom picker that should allow one selection. A different selection should be made by removing the first selection. 

Currently, when a user types, makes a selection, and then keeps typing, the input is filled with 50 seemingly random selections. These selections do not save. 

When typing slower and allowing the dropdown to fully load, it works as wanted. Any ideas on how to fix this? Thank you

 a!pickerFieldCustom(
                label: "Name",
                labelPosition: "ABOVE",
                placeholder: "--- Select a Name ---",
                saveInto: local!selectedPerson,
                suggestFunction: rule!AST_GETNAMES,
                selectedLabels: if(
                  a!isNullOrEmpty(local!selectedPerson), 
                  null, 
                  index(rule!AST_GETUSERFROMARRAY(suggestionText:local!selectedPerson), "data")
                ),
                value: if(
                  a!isNullOrEmpty(local!selectedPerson), 
                  null, 
                  index(rule!AST_GETUSERFROMARRAY(suggestionText:local!selectedPerson), "data")
                ),
                required: true,
                validations: {},
                disabled: false,
                maxSelections: 1, /* Only allow one name to be selected at a time */
              ),

5 replies

davidj137213
October 11, 2024

Check the output of this rule....

rule!AST_GETUSERFROMARRAY(suggestionText:local!selectedPerson)

I think that it's returning that 50 random selections....

October 11, 2024

Thank you, I've been looking there and I'm not seeing the issue. If you have a chance to take a look, I'd really appreciate it. 

a!localVariables(
  local!query: if(
    or(
      isnull(ri!suggestionText),
      length(ri!suggestionText) = 0
    ),
    null, /* If suggestionText is empty or null, no query filters will be applied */
    a!queryLogicalExpression( 
      operator: "AND",
      filters: {
        a!queryFilter(
          field: "name",
          operator: "=",
          value: lower(ri!suggestionText[1]) /* Safeguard: Accessing the first element safely */
        )
      },
      ignoreFiltersWithEmptyValues: true
    )
  ),
  local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: 50
  ),
  local!result: a!queryEntity(
    entity: cons!DLP_ed_person_constant,
    query: a!query(
      logicalExpression: if(
        isnull(local!query),
        a!queryLogicalExpression(operator: "AND", filters: {}), /* Empty logical expression if query is null */
        local!query
      ),
      pagingInfo: local!pagingInfo
    ),
    fetchTotalCount: false
  ),
  a!dataSubset(
    data: if(
      isnull(local!result),
      {},
      a!forEach(
        items: local!result.data,
        expression: fv!item.displayName & " (" & fv!item.email & ")"
      )
    ),
    identifiers: if(
      isnull(local!result),
      {},
      a!forEach(
        items: local!result.data,
        expression: fv!item.name
      )
    )
  )
)

October 11, 2024

It's not clear to me. Provide more details.

If you have maxSelections:1, the component should not allow you to type anything once you have selected one item.

October 11, 2024

Agreed, that's what I can't figure out. I added the rule!AST_GETUSERFROMARRAY above if that adds context. Thank you

shanmathip7466
October 23, 2024

Hi [mention:19c354a47ef14ddfac6832b522fb8d60:e9ed411860ed4f2ba0265705b8793d05] ,

In the Picker Field, you have called the rule ---> index(rule!AST_GETUSERFROMARRAY(suggestionText:local!selectedPerson), "data")  in SelectedLabels And Values. This is the reason why you are getting 50 values (which is in batch size of your pagingInfo)

Give the same local variable in VALUE parameter as you have given in SAVEINTO parameter and in SelectedLabel try to add logic for how your selection value should be displayed.

  • selectedLabels -- what the user sees 
  • value - the underlying data/id associated with the selected options to store in the database

Please refer the link for how to configure Custom Picker Field