I am facing following issue: I need to retrieve users from the whole domain not just siteusers list at sharepoint so that can can manipulate them and for example add them to sharepoint groups.
I have following script:
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var loginName="domain\\username";
getUserEmailByLoginName(loginName);
});
function getUserEmailByLoginName(loginName) {
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers?$select=Email&$filter=substringof('"+loginName+"',LoginName)";
//execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
success: function (data) {
if(data.d.results.length>0){
alert(data.d.results[0].Email);
}
},
error: function () {
//alert("Failed to get details");
}
});
}
</script>
This one retrieves email from selected user. The problem is that if I enter users id who is not member of siteusers i dont retrieve anything. Is there a way how to lookup whole domain via javascript and then create user object out of it?
Thank you