0

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

enter image description here

Then in the Front End i have this result :

enter image description here

it's a non modified value even when i

I make:

$("#Superior").html(ArrayRetrieved.ImmediateSuperior.Title);

2 Answers 2

0

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 :)

0

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);
           });
       }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.