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
I assume you could use the Custom Picker for this, depending on the exact details of your use case.
I will look into that. What it is, is I have a Recordtype that pulls data from a database table, in that table I have, among other columns, a first name and a last name. I want to be able to display both when they are selecting the one they need.
That's completely configurable within the Custom Picker - you can set the preview labels and selected item labels to show any combination of the available data you're selecting from. For example, I've made a "user picker from database" component in the past wherein the label text shows first name, last name, username, and DB primary key.
Great. Would you be willing to share a snip it of the code?
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.
Worked Perfect, thank you
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)") ) )