Add content editor webpart into the sharepoint Page
Add the below script into it.
(function ($) {
$(document).ready(function () {
// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');
});
function loadUserData() {
jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
type: "GET",
headers: { Accept: "application/json;odata=verbose" },
success: function (data) {
if (data.d.DisplayName != null)
$("#lbl-MyProfileName").html(data.d.DisplayName);
$("#lbl-MyProfilePhoneNumberEmail").html(data.d.Email);
$("#lbl-MyProfileDesignation").html(data.d.Title);
if (data.d.PictureUrl != null) {
var encodedPictureURL = encodeURIComponent(data.d.PictureUrl);
$("#img-MyProfileImage").attr("src", "/_layouts/15/userphoto.aspx?size=L&url=" + encodedPictureURL);
}
if (data.d.UserProfileProperties != null) {
$.each(data.d.UserProfileProperties.results, function (index, value) {
if (value.Key == "WorkPhone") {
$("#lbl-MyProfilePhoneNumber").html(data.d.UserProfileProperties.results[index].Value);
}
else if (value.Key == "Office") {
$("#lbl-MyProfileLocation").html(data.d.UserProfileProperties.results[index].Value);
}
});
}
},
error: function (jqxr, errorCode, errorThrown) {
alert("Error: " + args.get_message());
}
});
}
})(jQuery);
Add the below script into it.
(function ($) {
$(document).ready(function () {
// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');
});
function loadUserData() {
jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
type: "GET",
headers: { Accept: "application/json;odata=verbose" },
success: function (data) {
if (data.d.DisplayName != null)
$("#lbl-MyProfileName").html(data.d.DisplayName);
$("#lbl-MyProfilePhoneNumberEmail").html(data.d.Email);
$("#lbl-MyProfileDesignation").html(data.d.Title);
if (data.d.PictureUrl != null) {
var encodedPictureURL = encodeURIComponent(data.d.PictureUrl);
$("#img-MyProfileImage").attr("src", "/_layouts/15/userphoto.aspx?size=L&url=" + encodedPictureURL);
}
if (data.d.UserProfileProperties != null) {
$.each(data.d.UserProfileProperties.results, function (index, value) {
if (value.Key == "WorkPhone") {
$("#lbl-MyProfilePhoneNumber").html(data.d.UserProfileProperties.results[index].Value);
}
else if (value.Key == "Office") {
$("#lbl-MyProfileLocation").html(data.d.UserProfileProperties.results[index].Value);
}
});
}
},
error: function (jqxr, errorCode, errorThrown) {
alert("Error: " + args.get_message());
}
});
}
})(jQuery);
No comments:
Post a Comment