I met with an interesting requirement like, on the EditForm.aspx, we need to update some of the values based on the User Profile Property. As all of us know that the EditForm.aspx is a SitePage, from which we need to retrieve the value using the Javascript alone. Hence, I added a script editor webpart on the page and kept the below code over there.
function GetProfileProperty() {
$.ajax({
url: "/_api/sp.userprofiles.peoplemanager/getmyproperties",
type: "GET",
headers: { "accept": "application/json;odata=verbose" },
success: function (msg) {
var x = msg.d.UserProfileProperties.results;
for (var i = 0; i < x.length; i++) {
if (x[i].Key == "SPS-School") {
alert(x[i].Value);
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (x[i].Value == "TVS") {
if (inDesignMode == "1") {
// page is in edit mode
// Do the Logics Here.
}
else {
// page is in browse mode
}
}
else {
if (inDesignMode == "1") {
// page is in edit mode
// Do the Logics here.
}
else {
// page is in browse mode
}
}
}
}
},
error: function (msg) {
alert(msg.responseText);
} });
}
In this example, I took the Property “SPS-School” and compared against the School “TVS” – The one where I studied..
Happy Coding.
Sathish Nadarajan.
Leave a comment