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">
  • Have you tried out AJAX? – user2536 Mar 13 '12 at 16:22

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


| 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);
| 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.

| improve this answer | |
  • Please make sure you avoid linking to answers. That example link is broken. Should summarize the contents or provide a brief example here so this becomes an authoritative source. – vapcguy Mar 19 '19 at 15:06

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.