Custom picker for Searching users

Hi,

I have a requirement to create a search filed for searching users List. The users list is getting from an Query Rule(table from DB) not from any groups.

I have achieved this by using the following code.

Code:

a!pickerFieldCustom(
label:"Select Re-assignee",
maxSelections:1,
suggestFunction: rule!ucArrayPickerFilter(
filter:_ ,
labels: local!reassignChoiceLabel,
identifiers: local!reassignChoiceValue
),
selectedLabels:a!forEach(
items: local!selectedAssignee,
expression: index(touniformstring(local!reassignChoiceLabel), wherecontains(fv!item, touniformstring(local!reassignChoiceValue)))
),
value:local!selectedAssignee,
saveInto:local!selectedAssignee,
labelPosition:"ADJACENT",

)

-----------------------------------------

rule using in the suggest function

rule: ucArrayPickerFilter

I'm getting the user's list while searching with User Names(below snippet) but my requirement is, i should get users list even if we search with an user id (both user name and user id should work).

 

Please suggest.

Thanks in advance

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to Harris

    Here's a simple version.  This will allow the end user to type a partial first name OR partial last name OR partial username, OR the user ID.  The first and last names must begin with the search string, but the search string can match any part of the username.

    a!queryLogicalExpression(
      operator: "OR",
      filters: {
        a!queryFilter(
          field: "firstName",
          operator: "starts with",
          value: ri!input
        ),
        a!queryFilter(
          field: "lastName",
          operator: "starts with",
          value: ri!input
        ),
        a!queryFilter(
          field: "username",
          operator: "includes",
          value: ri!input
        ),
        a!queryFilter(
          field: "userId",
          operator: "=",
          value: tointeger(ri!input),
          applyWhen: not(isnull(tointeger(ri!input)))
        )
      }
    )

  • 0
    Certified Lead Developer
    in reply to Harris

    Here's a more complex version I've used recently with a nested logical expression - basically this lets a user enter a few search terms separated by a space, and the query will return anything that matches all of them.  So if you're searching for "Mike Schmitt", you could type "Mi Sc", which would match me as well as "Minnie Schaffer" for example.  You could easily extend this to also allowing the username and/or user ID to be included as search terms following my simpler example above.

    a!queryLogicalExpression(
      operator: "AND",
      logicalExpressions: a!forEach(
        if(isnull(ri!input), {}, split(ri!input, " ")),
        a!queryLogicalExpression(
          operator: "OR",
          filters: {
            a!queryFilter(
              field: "firstName",
              operator: "includes",
              value: fv!item,
              applyWhen: not( isnull( fv!item ) )
            ),
            a!queryFilter(
              field: "lastName",
              operator: "includes",
              value: fv!item,
              applyWhen: not( isnull( fv!item ) )
            )
          }
        )
      )
    )