Get user information using client object model in SharePoint 2013

InfoPath alternatives for form designing SharePoint

In this post we will discuss how we can get user information using client object model code in SharePoint 2013.

Also you can check out:

– Cross-site publishing in SharePoint Server 2013

– Get all subsites information using SharePoint client object model

– Get current zone in SharePoint 2010

Below is the full code:

var userNameList=new Array();
function getAllUserNames() {
//generate query

var query = url + “_vti_bin/listdata.svc/UserInformationList()/?$select=Name,Id&$filter=ContentType eq ‘Person'”;
jQuery.ajax({
url: query,
async:false,
success: function (data) {
//loop though the data
//alert(data);
$(data).find(“content”).each(function () {
var userID = 0;
var strName = “None”;

//get the data
userID = $(this)[0].childNodes[1].childNodes[3].textContent;
strName = $(this)[0].childNodes[1].childNodes[1].textContent;

//add to dictionary as well
addItemToDictionary(userID, strName);
});
}
});
}

function addItemToDictionary(key, value, arrayName) {
if (typeof arrayName != ‘undefined’ && arrayName != null) {
arrayName.push(new keyvaluePair(key, value));
}
else {
userNameList.push(new keyvaluePair(key, value));
}
}

function keyvaluePair(id, value) {
if (typeof id != ‘unidentified’ && id != null) {
this.id = id;
this.value = value;
}
}

Similar SharePoint 2013 Tutorials


Leave a Reply