Hello Techies,
I wrote the below code to fetch current user and manager name - it works well on Chrome but on IE it doesn't work on page load for first time. But when I refresh the page it works. Anybody came across this issue.
$(document).ready(function () {
SP.SOD.executeFunc('sp.js', null, function () {
retrieveUserInfo();
})
});
function retrieveUserInfo() {
$("nobr:contains('Claim ID')").parent('h3').parent('td').parent('tr').hide();
var currentuserName = $().SPServices.SPGetCurrentUser({
fieldName: "Title"
});
var managerName;
$().SPServices({
operation: "GetUserProfileByName",
async: false,
AccountName: $().SPServices.SPGetCurrentUser(),
completefunc: function (xData, Status) {
$(xData.responseXML).find("PropertyData > Name:contains('Manager')").each(function () {
managerName = $(this).parent().find("Values").text();
});
}
});
var PickerTitle = "Employee";//Employee is Column name
$('input[title="' + PickerTitle + '"]').val(currentuserName).attr('size', 40);
$('div[title="' + PickerTitle + '"] span.ms-helperText').hide();
// Select the target user field from the dictionary of user fields on the page.
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[$('[title="' + PickerTitle + '"]')[0].id];
// Resolve the user using the value set in the input field.
peoplePicker.AddUnresolvedUserFromEditor(true);
var mgrName = "Employee Manager"; //Employee Manager is column Name
$('input[title="' + mgrName + '"]').val(managerName).attr('size', 40);
$('div[title="' + mgrName + '"] span.ms-helperText').hide();
var peoplePicker1 = SPClientPeoplePicker.SPClientPeoplePickerDict[$('[title="' + mgrName + '"]')[0].id];
peoplePicker1.AddUnresolvedUserFromEditor(true);
SPUtility.GetSPField('Employee').MakeReadOnly();// To make the columns as read-only
SPUtility.GetSPField('Employee Manager').MakeReadOnly();// To make the columns as read-only
}