0

I need to show the User profile Picture, Department, and location for every individual user who is Creating or adding the document to the library. I think we need to get the properties based on Authors name? I tried, but I got only current user Properties. please suggest me some idea to achieve this.

2 Answers 2

1

Try as below using REST API:

var accountName = 'domain\user';
$.ajax({
        url: "https://sitecollectionurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            console.log(data);                 
        },
        error: function (data) {
            console.log(JSON.stringify(data));
        }
});

If you are using JSOM, try below code:

var personProperties;

SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {
   // Make sure PeopleManager is available 
   SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function() {   
        getUserProperties();
   });

});

function getUserProperties() {

    // Replace the placeholder value with the target user's credentials.
    var targetUser = "domainName\\userName";

    // Get the current client context and PeopleManager instance.
    var clientContext = new SP.ClientContext.get_current();
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    // Get user properties for the target user.
    // To get the PersonProperties object for the current user, use the
    // getMyProperties method.
    personProperties = peopleManager.getPropertiesFor(targetUser);

    // Load the PersonProperties object and send the request.
    clientContext.load(personProperties);
    clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
}

// This function runs if the executeQueryAsync call succeeds.
function onRequestSuccess() {
        console.log(personProperties.get_userProfileProperties()['Department']);    
}

// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
    console.log(args.get_message());
}
2
  • Thanks, I hope above script is for getting the Current user Profile properties right? But I need to get User profile properties based on Created by column
    – Debugger
    Jan 3, 2017 at 9:31
  • var targetUser = "domainName\\userName"; or accountName='domain\user', here you can pass the author name. So, whatever is the user you pass in these variables, the properties of that account will be fetched. Jan 3, 2017 at 9:33
3

You can use following rest api URL to get required properties

Get all properties of Specific User:

For Office 365/SharePoint Online: http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|[email protected]'

For SharePoint 2013 On-Premise: http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\username'

Get Specific UserProfile Property of Specific User:

For Office 365/SharePoint Online: http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='i:0%23.f|membership|[email protected]'

For SharePoint 2013 On-Premise: http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='domain\username'

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.