I am trying to display 2 fields in a record picker.

Certified Associate Developer

I have a functioning record picker that searches a first name field, but would also like it to display a second field, a last name filed.  Any thoughts?

  Discussion posts and replies are publicly visible

Parents Reply Children
  • +1
    Certified Lead Developer
    in reply to AllenP

    Basically in mine I have the custom picker save the "userId", being their primary key id from the users table, into a rule input, then I assemble a list of labels for selected userIds, to display in the 'selectedLabels' parameter.

    selectedLabels: if(
      rule!isEmpty(ri!selectedUserIdList),
      {},
      a!forEach(
        rule!QueryEntity_Users(userIds: ri!selectedUserIdList, columns: {"firstName", "lastName", "username", "userId"}).data,
        fv!item.firstName & " " & fv!item.lastName & " (" & fv!item.username & ") [" & fv!item.userId & "]" & if(fv!item.isActive, "", " (Deactivated)")
      )
    ),

    Note that this code snippet relies on you having a robustly-defined Query Entity rule into your "users" table, including the ability to filter on userIds and enter an array of column names to exclusively query.  These can all be tweaked one way or the other by adjusting the code to your liking.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Worked Perfect, thank you

  • 0
    Certified Lead Developer
    in reply to AllenP

    After some further thought, it occurred to me that the above code snippet will tend to mix up the ordering of selected users in your list (assuming you're planning to allow picking of more than 1; otherwise disregard this).  To fix that, you can swap out the a!forEach logic there with the following... it does query slightly less efficiently, but shouldn't make a big difference overall, while preserving the ordering of the users selected.

    a!forEach(
      ri!userIdList,
      a!localVariables(
        local!userCdt: rule!queryEntity_Users(
          personIds: fv!item,
          columns: {"firstName", "lastName", "username", "userId", "isActive"}
        ).data,
        
        local!userCdt.firstName & " " & local!userCdt.lastName & " (" & local!userCdt.username & ") [" & local!userCdt.personId & "]" & if(local!userCdt.isActive, "", " (Deactivated)")
      )
    )