SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to get user information via the JavaScript Client OM? Something similar to the clientContext.Web.EnsureUser(userName) method. I am aware that there is the SPService JQuery library, but if I can do this via the Client Object Model, I would prefer that. And just to be clear: I am NOT talking about the current logged in user. I want to verify the existence of a user in a manner similar to the people picker control.

Edit: Here is some example code... It assumes JQuery is loaded. Just plug it into an HTML Form webpart.

<input type="text" id="user-name">&nbsp;<input type="button" id="myButton" value="check name" />
<script type="text/javascript">

    function verifyUser(userName){
       var context = new SP.ClientContext.get_current(); 
       var web = context.get_web();
       var user = web.ensureUser(userName);

           function(sender, args) {showUserData(user);}, 
           function(sender, args) {alert("Error: " + args.get_message());} 
    function showUserData(user){
        $('#display-user-info').html('<tr><td>Name: '+user.get_title()+'</td><td>&nbsp;Email: '+user.get_email()+'</td></tr>'
<table id="display-user-info">
share|improve this question
Have you tried out AJAX? – Daniel Ziga Mar 13 '12 at 16:22
up vote 4 down vote accepted

There is an ensureUser Method in the JS Client Object Model:

share|improve this answer
Thanks! I was browsing the object in debugger and must have missed that! – Robert Kaucher Mar 13 '12 at 17:22
Nice, haven't seen that one, handy indeed :) – Anders Aune Mar 13 '12 at 18:45

How to retrieve UserInfo by UserName from UserInfo List via CSOM

function getUserInfo(userName,Success,Error)
   var context = new SP.ClientContext.get_current();
   var userInfoList = context.get_web().get_siteUserInfoList();
   var query = new SP.CamlQuery();
   var viewXml = "<View> \
                    <Query> \
                       <Where> \
                           <Eq><FieldRef Name='UserName' /><Value Type='Text'>" + userName + "</Value></Eq> \
                       </Where>  \
                    </Query> \
                    <RowLimit>1</RowLimit> \
   var items = userInfoList.getItems(query);
       if(items.get_count() > 0) {
          var item = items.itemAt(0);
       else {

       console.log('User Id: ' + userInfo.ID);
share|improve this answer

You could build a function using the SP.Web.siteUserInfoList.

And here is a link to an example

I'm not aware of a method like EnsureUser, there is a UserCollection with some methods for retrieving users, but looks like you have to get a site group first.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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