Custom Picker selection incorrectly populating field

Certified Associate Developer

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 */
              ),

  Discussion posts and replies are publicly visible

  • Check the output of this rule....

    rule!AST_GETUSERFROMARRAY(suggestionText:local!selectedPerson)

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

  • 0
    Certified Associate Developer

    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.

  • 0
    Certified Associate Developer
    in reply to David Jimenez Calleja

    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
          )
        )
      )
    )

  • 0
    Certified Associate Developer
    in reply to Yogi Patel

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

  • 0
    Certified Senior Developer
    in reply to Kylie

    Hi  ,

    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