1

I want to retrieve a custom field from the user profile property with rest. The property is searchable in search. Name of the custom properties "CompanyNumber"

But when I try to use http://companyname.com/site/sitename/_api/SP.UserProfiles:peopleManager/GetMyProperties

it does not retieve the custom properties, only the built in properties like :

  • AccountName
  • DirectReports
  • DisplayName
  • Email
  • ....

I get a node that says UserProfileProperties where there is a Key? But how do I use this?

INFOPATH

I have to use infopath so pure javascript does not work :(

What I realy want to do is to type in the CompanyNumber and then the adress / postnumber / etc. get autopopulated

2 Answers 2

1

Try this

var theData = {
 "propertiesForUser": {
    "__metadata": { "type": "SP.UserProfiles.UserProfilePropertiesForUser" }, 
    "accountName": "domain\username",
    "propertyNames": ["CompanyNumber"]
     }
};

var requestHeaders = {
    "Accept": "application/json;odata=verbose",
    "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
};

jQuery.ajax({
    url:_spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertiesFor",
    type:"POST",
    data: JSON.stringify(theData),
    contentType : "application/json;odata=verbose",
    headers: requestHeaders,
    success:function(data){
        console.log(data);
    },
    error:function(jqxr,errorCode,errorThrown){
        console.log(jqxr.responseText);
    }
});

Source : http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

4
0

Please try below code. It worked for me for getting current user custom property details. Make sure the CompanyNumber is internal name of your field in User Profile Service.

//Display User profile properties
function getMyUserProfile(success, error) {
    var siteUrl = _spPageContextInfo.siteAbsoluteUrl; //You can replace this with your site URL too. i.e http://anysite.com
    $.ajax({
        url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            var json = $.parseJSON(JSON.stringify(data.d));
            for (var i = 0; i < data.d.UserProfileProperties.results.length; i++) {
                if (data.d.UserProfileProperties.results[i].Key == "CompanyNumber") {
                    alert("Your Custom Property Company Number is : " + data.d.UserProfileProperties.results[i].Value);
                }
            }
        },
        error: error
    });
}

// Usage   
getMyUserProfile(function (properties) {},
      function (data) {
          console.log(JSON.stringify(data));
      });

Try below URL for more details.

http://fixingsharepoint.blogspot.com/2016/04/how-to-get-custom-user-profile-property.html

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.