2

I know how to get all users in share point site by using c# code ,but i want to get all site users using csom javscript. Any ideas?

2

Just make a ajax request to the following url, and it will give you all site users

/_api/web/siteusers

Full code using rest API

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function(data) {
        console.log(data.d.results);
    },
    error: function(error) {
        alert(JSON.stringify(error));
    }
});

Full code using csom javascript

function GetAllUsers() {
    var clientContext = new SP.ClientContext.get_current();

    var web = clientContext.get_web();

    var userInfoList = web.get_siteUserInfoList();

    this.collListItem = userInfoList.getItems();

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded(sender, args) {

    var item = collListItem.itemAt(0);

    var profileNotes = item.get_item(‘Notes’);
    alert(profileNotes);
}

function onQueryFailed(sender, args) {}
}

Above code taken from here

  • sandbox solutions it is posible? – chakri Oct 7 '15 at 6:59
  • Yup ...... Make sure jquery is in your page – Atish Dipongkor - MVP Oct 7 '15 at 7:01
  • Hi There, Mine is SP 2010 on tyring this script i am getting below error. "Microsoft.SharePoint.Client.UnknownError" It goes in error call back – shoab Oct 10 '17 at 5:31
  • I got the same problem like shoab on SP 2013. Does nobody has an answer to this? – modiX Nov 21 '17 at 9:25

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.