0

My function is :

function UpdatePerform() {
        var clientContext = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);
        var oList = clientContext.get_web().get_lists().getByTitle(ListOnboarding);

        var item = oList.getItemById($("#idC").val());

        var Superior = $("#Superior").val();
        var Employees = $("#SuperEmployeesior").val();

        item.set_item('ImmediateSuperior', Superior);
        item.set_item('EmployeesReportingToThisUser', Employees);

    item.update();

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded_SaveTo), Function.createDelegate(this, this.onQueryFailed_SaveTo));
}

When i want to update the person field, it empty it! can anyone help me please?

2
  • I guess the .val() method of jQuery returns a string. You need to probably use the EnsureUser-method on this string (if it's for example domain\user) and cast the result to New-Object Microsoft.SharePoint.Client.FieldUserValue
    – SteffPoint
    Commented Dec 2, 2019 at 19:06
  • Steff i used this to update the single selection in the People Picker : var Superior = $("#Superior").getUserInfo(); and when i debug i can see the value of Superior 0: "i:0#.f|membership|[email protected]" But finally i get Unknown Error
    – Jihen
    Commented Dec 2, 2019 at 19:16

1 Answer 1

0

This is the solution :

function UpdatePerform() {
var clientContext = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(ListOnboarding);

var item = oList.getItemById($("#idC").val());

var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.Employees_TopSpan;
// Get information about Employees
var Employees = peoplePicker.GetAllUserInfo();

var Users = new Array();
if (Employees != 0) {

    for (var i = 0; i < Employees.length; i++) {
        var arryuser = Employees[i];
        Employ = arryuser["DisplayText"];
        Users.push(SP.FieldUserValue.fromUser(Employ));
    }
} else Users = null;

 item.set_item('EmployeesReportingToThisUser', Users);

item.update();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded_SaveTo), Function.createDelegate(this, this.onQueryFailed_SaveTo));
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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