How to get username on the basis of customField1?

Certified Associate Developer

Hello All,

I have requirement to fetch user name on the basis of customField1. How can I achieve this? Thanks in advance

  Discussion posts and replies are publicly visible

Parents
  • Hi,

    Below is the code I used to create such a rule.

    This rule uses one input "customField1" (Text) and a constant containing a group with all users. You can use this rule to pass in the customField1 value you are searching for to return an array of users.

    with(
    local!userDictionary: a!forEach(
    items: getdistinctusers(
    cons!AllUsers
    ),
    expression: {
    user: fv!item,
    customField1: user(
    fv!item,
    "customField1"
    )
    }
    ),
    index(
    local!userDictionary,
    "user",
    wherecontains(
    ri!customField1,
    touniformstring(
    local!userDictionary.customField1
    )
    ),
    null
    )
    )

    I hope this is useful.
    Brad
  • I realized there is also a plug-in titled "Get Users By" which contains a function fn!getusersby which allows you to search for users by specific fields in a user profile that will accomplish what you're looking for with far less code. I would recommend using this plug-in if you are able to install plug-ins.

    Here is a snippet of the code that would be required to retrieve users with a customField1 value of "Test" using this plug-in:

    fn!getusersby(
    recordValue: "Test",
    recordType: 6,
    operator: "1"
    )
Reply
  • I realized there is also a plug-in titled "Get Users By" which contains a function fn!getusersby which allows you to search for users by specific fields in a user profile that will accomplish what you're looking for with far less code. I would recommend using this plug-in if you are able to install plug-ins.

    Here is a snippet of the code that would be required to retrieve users with a customField1 value of "Test" using this plug-in:

    fn!getusersby(
    recordValue: "Test",
    recordType: 6,
    operator: "1"
    )
Children
No Data