Wednesday, October 14, 2015

How to retrieve user profile detail In java script Sharepoint

<script src="../_layouts/15/JS/Slider/jquery.min.js"></script>

var personProperties;
$(document).ready(function () {
        try {
// SP.UserProfiles.js script file loaded
SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js');
  } catch (e) {
            alert("Ready Error:" + e);
        }
     
    });

function getUserProperties() {


var targetUser = "raghupc\\raghu";


var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);


personProperties = peopleManager.getPropertiesFor(targetUser);


clientContext.load(personProperties);
clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
    }

//Sucess function
function onRequestSuccess() {

var messageText = " \"DisplayName\" property is "    + personProperties.get_displayName();


messageText += "Department"  + personProperties.get_userProfileProperties()['Department'];
$get("results").innerHTML = messageText;
}

//Fail function
function onRequestFail(sender, args) {
    $get("results").innerHTML = "Error: " + args.get_message();
}
</script>

No comments:

Post a Comment