0

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

3

1 Answer 1

1

You are making the wrong API call. You should instead use /_api/SP.UserProfiles.PeopleManager/GetPropertiesFor

See Retrieve userprofiles by REST API for more information.

1
  • Thank you very much, with additional code i managed to achieve my goal.
    – Rudolf
    Apr 16, 2019 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.