Resolve user by display name

Home Forums Autocomplete Resolve user by display name

Tagged: 

Viewing 2 reply threads
  • Author
    Posts
    • #30529
      Leonid
      Participant

        Hi Alex and all,
        Wondering if someone knows of the way to populate peoplepicker by user’s Display Name. Unfortunately neither email nor Account ID are available.

      • #30548
        Alexander Bautz
        Keymaster

          Not sure what you mean – just use setFieldValue like this:

          setFieldValue("Internal_name_of_people_picker", "Display name of user");

          This will however NOT work if you have a comma in the user name – then you would have to get the login name like this:

          function getUserByTitle(title){
              var user = spjs.utility.queryItems({
                  "listName": "UserInfo",
                  "query": "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>User, Test</Value></Eq></Where>",
                  "viewFields": ["ID","Name"]
              });
              return user.count > 0 ? user.items[0] : null;    
          }
          // Get the user like this:
          var user = getUserByTitle("User, Test");
          if(user !== null){
              setFieldValue("Internal_name_of_people_picker", user.Name);
          }

          Alexander

        • #30586
          Leonid
          Participant

            Thanks Alex,
            In fact, display name has a comma “Daw, A. John”, whereas UserInfo shows name as “John Daw”. I’ll keep digging

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.