0

I will explain how I am currently doing my REST calls, by the hyperlinks.

_vti_bin/ListData.svc/UserInformationList?$select=Account&$filter=substringof('Joe',Name)
_api/sp.userprofiles.peoplemanager/GetUserProfilePropertyFor(accountname=@v, propertyname='Manager')?@v='i:0#.w|domain\joe.wallis'
_vti_bin/ListData.svc/UserInformationList?$select=Id&$filter=Account eq 'domain\Jane.doe'
  • First off I get my account name, then I proceed to get my managers ID via their account name, but their Account is i:0#.w|domain\Jane.doe, not domain\Jane.doe, which is returned from GetUserProfilePropertyFor.

  • I can't use $filter=substringof('domain\Jane.doe',Account) as it will return domain\Jane.doe2 along with domain\Jane.doe.admin.

  • If I could just do GetUserProfilePropertyFor(accountname=@v, propertyname='ManagerId'), it would solve this all, but as far as I know there is no such URL.

  • And finally, I would prefer to have a method that can be converted to office 365 with ease. And so doing $filter=substringof('i:0#.w|{Manager}',Account) would not work.

But I understand beggars can't be choosers.


I'm using Angular.js and so my AJAX requests are different to JQuery.
The headers for my AJAX calls are:

$httpProvider.defaults.headers.common['X-RequestDigest'] =
    document.getElementById('__REQUESTDIGEST').value;
$httpProvider.defaults.headers.common.Accept = 'application/json;odata=verbose';
$httpProvider.defaults.headers.post['Content-Type'] = 'application/json;odata=verbose';

Where the AJAX calls are:

var search = 'Joe';

$http.get(
    _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/ListData.svc/UserInformationList' +
    "?$select=Account&$filter=substringof('" + search + "',Name)"
).then(getManagerAccount);

function getManagerAccount(response) {
    $http.get(
        _spPageContextInfo.webAbsoluteUrl +
        '/_api/sp.userprofiles.peoplemanager/' +
        "GetUserProfilePropertyFor(accountname=@v, propertyname='Manager')?@v='" +
        encodeURIComponent(response.data.d.results[0].Account) + "'"
    ).then(getManagerId);
}

function getManagerId(response) {
    $http.get(
        _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/ListData.svc/UserInformationList' +
        "?$select=Id&$filter=Account eq '" +
        encodeURIComponent(response.data.d.GetUserProfilePropertyFor) + "'"
    ).then(function (response) {
        response = response.data.d.results[0];
        if (response) {
            alert(response.Id);
        } else {
            alert("Could not get the manger's ID.");
        }
    });
}

In short is there any way to get the correct manager Id from either a user Account or Id.

1

What are you actually retrieving represents the claims-aware user identifier which in your case, because it is for Windows (i:0#.w part), which in SharePoint 2013 is the native one (unless you have created specifically your web app using Classic - that you shouldn't). One can convert between classic login and claims-aware, example here http://blog.mastykarz.nl/programmatically-converting-login-name-claim/.

To understand how this work please consult http://www.wictorwilen.se/Post/How-Claims-encoding-works-in-SharePoint-2010.aspx. Obviously the simplest would be split string, but not recommended as multiple authentication providers could be configured and each will have a different prefix.

Also, I could notice you are relying on the User information List which might not be a good idea because that Identifier is specific to each Site collection (unless that is what you are chasing).

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.