Get user information using client object model in SharePoint 2013

InfoPath alternatives for form designing SharePoint

This SharePoint 2013 client object model tutorial explains, how we can get user information using client object model code in SharePoint 2013.

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;
}
}

Hope this tutorial will help you.


You May Also like the Following SharePoint Online Tutorials:

Leave a Reply