Get PeoplePicker value Edit Form
-
08-02-2021 - |
Question
I want to get the Name of the User in the people picker Field of the Edit form.
My Javascript is as below :
$("#Superior").html(ArrayRetrieved.ImmediateSuperior.Id);
The result is the below
Then in the Front End i have this result :
it's a non modified value even when i
I make:
$("#Superior").html(ArrayRetrieved.ImmediateSuperior.Title);
Solution
So, to do that, for one User, i found this solution
// RETRIEVE ONE USER
var GetOneUser = function (UserIDToUse) {
if (UserIDToUse != null) {
var dfd = $.Deferred(function () {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/GetUserById(" + UserIDToUse + ")",
type: "GET",
headers: {
Accept: "application/json; odata=verbose"
},
success: function (data) {
dfd.resolve(data.d);
},
error: function () {
dfd.reject(args.get_message());
}
});
});
return dfd.promise();
} else {
return $.Deferred().resolve().promise();
}
};
and then we call it in the Retrieve Function like that :
GetOneUser(ArrayRetrieved.ImmediateSuperior.Id).done(function (user) { $("#Superior").spPeoplePicker(false, user); });
But i'm looking now for the multiUsers function! If you can help me, or if i find the solution, i will post it again :)
OTHER TIPS
So, for multiUsers this is the solution : So just in the retrieve function we add this code :
if (ArrayRetrieved.EmployeesReportingToThisUser.results.length != 0 && ArrayRetrieved.EmployeesReportingToThisUser != null) {
for (var j = 0; j < ArrayRetrieved.EmployeesReportingToThisUser.results.length; j++) {
GetUser(ArrayRetrieved.EmployeesReportingToThisUser.results[j].Id).done(function () {
$("#Employees").spPeoplePicker(true, ArrayRetrieved.EmployeesReportingToThisUser.results);
});
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange