2

I want to get the log-in name of user from people picker control using jquery.

I have a code which displays the display name of the user but I am not able to get the login name.

Code is as follows:

$(document).ready(function () {
$("input[title='Project Owner']").focusout(function () {    

    var loginName = $("span.ms-entity-resolved").attr("title");

    alert("Login Name:" + loginName);

    var displayName = $("span.ms-entity-resolved div:first-child").attr("displaytext");

    alert("Display Name :" +displayName);

});

});

Here Project Owner is name of the PeoplePicker control.

How do I get the login name?

1

I did some tricks and found the solution finally, I don't know it is the optimal solution but it works in my case.

The code is here:

$(document).ready(function () {
$("input[title='Project Owner']").focusout(function () {    

    var loginName = $("span.ms-entity-resolved").attr("ID");

    var start = loginName.indexOf(":");

    var end = loginName.indexOf("_Processed");

    var finalUserName = loginName.substring(start-1, end);

    alert(finalUserName);
});


});
0
var ctx = new SP.ClientContext();
var user = ctx.get_web().get_currentUser();
ctx.load(user);
ctx.executeQueryAsync(function() {
    alert(user);
});​

above is using sharepoint javascript object model sp.js, you cant do it the way your doing it in your example!

Getting the username from javascript client object model?

also look here:

Get current user in Client Object Model with javascript?

EDIT

sorry i missunderstood your question!

$(document).ready(function() 
{ 
     $("input[title='JM ID']").focus(function()   
     { 
          var User = $("textarea[title='People Picker']").val(); 
          alert(User);
     }); 
}); 

that should get the user name from people picker!

http://ronsp.wordpress.com/2010/01/19/get-value-from-people-picker-using-jquery/

EDIT

strange should of worked! have you tried the full code?

$(document).ready(function() 
{ 
   $("input[title='JM ID']").focus(function()   
   { 
      var User = $("textarea[title='People Picker']").val().split("\\"); 
      alert(User);
   }); 
}); 

or

$(document).ready(function() 
{ 
   $("input[title='JM ID']").focus(function()   
   { 
      var User = $("textarea[title='People Picker']").val().split("\\"); 
      alert(User[0]);
      alert(User[1]);
   }); 
});
  • Will it get the current logged in user or the user that is entered in the PeoplePicker? – users1100 Nov 1 '13 at 10:51
  • just ammended my answer – Ali Jafer Nov 1 '13 at 10:59
  • I tried the code and I am getting undefined in the alert box :( – users1100 Nov 1 '13 at 11:02
  • what version of sharepoint are you using? – Ali Jafer Nov 1 '13 at 11:13
  • Sharepoint 2013... – users1100 Nov 1 '13 at 11:14
0

You can get login name using key property,

PickerEntity objEntity = (PickerEntity)peUser.ResolvedEntities; loginName = objEntity.Key;

and Display name using DisplayText property,

displayName = objEntity.DisplayText;

  • This is using C#, not jQuery. – vapcguy Aug 24 '15 at 15:55
0

Actually it is alot easier - You can access a normal peoplepicker in SP2013 the same way you would access a clientside one.

The Problem is, that you need to know the ID to identify the peoplepicker. Alternatively you can iterate over the global Object containing the PeoplePicker's.

If you check out the SPClientPeoplePicker.SPClientPeoplePickerDict object in your debugging console, there are all peoplepicker of this page stored in it (iterate here to get all peoplepicker).

enter image description here

You can access the entered user's information like this:

SPClientPeoplePicker.SPClientPeoplePickerDict[yourPickersID].GetAllUserInfo()

Example User Now every object has stored the properties of an user that was entered in the picker.

enter image description here

Here's an example for a group Example Group

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.