8

In my Sp2013, I tried this link

http://mysite/_api/SP.UserProfiles.PeopleManager/GetMyProperties

and it gets all properties including the custom managed ones from crawling. And one of them is called Office which comes in the xml from above link.

This is in the big xml thats returned

            <d:element m:type="SP.KeyValue">
                <d:Key>Office</d:Key>
                <d:Value>12-R</d:Value>
                <d:ValueType>Edm.String</d:ValueType>
            </d:element>

But then if I try this

http://mysite/_api/SP.UserProfiles.PeopleManager/GetMyProperties/Office

it says Office is not found...

How can I get it to return that?

Thanks

  • have you tried with other property? may be property name is different what you typing...also try this way siteurl/_api/SP.UserProfiles.PeopleManager/… – Waqas Sarwar MVP Aug 18 '15 at 17:59
  • I tried it, and the pictureUrl, and also even email works. Its just the custom managed ones that don't work. – omega Aug 18 '15 at 18:01
  • have u tried Select? – Waqas Sarwar MVP Aug 18 '15 at 18:09
  • yess and it didnt work – omega Aug 18 '15 at 19:01
  • Not sure if it's helpful but we use CSWP to achieve this since we can do dynamic query in CSWP. All we put is "Office:{User.Office}" then the search will automatically filter on current user's office, or you can default to current user's office and sort by that property. – YogaPanda Aug 31 '16 at 18:12
3

If you want to get only the specific property value then use "getuserprofilepropertyfor" & pass the current user login name

$.ajax({
      url: "http://<site url>/_api/sp.userprofiles.peoplemanager
        /getuserprofilepropertyfor(accountName=@v, propertyname='Office')
            ?@v='i%3A0%23.f%7Cmembership%7Csekhar%mydomain.onmicrosoft.com'",
      type: "GET",
      headers: { "accept": "application/json;odata=verbose" },
      success: successHandler,
      error: errorHandler
    });
  • this worked, but how can I do this for current user? – omega Aug 18 '15 at 18:05
  • use _spPageContextInfo.userLoginName to pass the current user login name if you are not an AD user. apply escapeProperly function before adding it to rest call escapeProperly(_spPageContextInfo.userLoginName) – sekhar Aug 18 '15 at 18:09
  • I tried alert(_spPageContextInfo.userLoginName); but it says undefined. – omega Aug 18 '15 at 18:10
  • 2
    But thats then 2 ajax calls (one to get username, then one more to get office). I only want 1 call – omega Aug 18 '15 at 18:15
1

Try below approach. It worked fine for me.

var siteUrl = "http://mysite";
$.ajax({
        url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
             for (var i = 0; i < data.d.UserProfileProperties.results.length; i++)
            {
                if(data.d.UserProfileProperties.results[i].Key == "Office")
                {
                    alert(data.d.UserProfileProperties.results[i].Value);
                }
            }

        },
        error: error
    });
-1

Try

http://mysite/_api/SP.UserProfiles.PeopleManager/getuserprofilepropertyfor(accountame=@v, propertyname='Office')?@v='*AccountName*'

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.