0

I need to set value into a ClientPeoplePicker, my list save the user as a SPUserField, I already get the id from the list.

Thanks and greetings

0

Try something like this:

function SetAndResolvePeoplePicker(fieldName, userAccountName) {
    var controlName = fieldName;
    var peoplePickerDiv = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");
    var peoplePickerEditor = peoplePickerDiv.find("[title='" + controlName + "']");
    var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];

    peoplePickerEditor.val(userAccountName);
    spPeoplePicker.AddUnresolvedUserFromEditor(true);

    //disable the field
    spPeoplePicker.SetEnabledState(false);

    //hide the delete/remove use image from the people picker
    $('.sp-peoplepicker-delImage').css('display','none');
}

Credit to: http://www.sharepointcolumn.com/sp2013-setting-people-picker-value-in-newform-aspx/

Alternatively you could use something like the SPUtility library, which simplifies the process to:

SPUtility.GetSPField('Display Name').SetValue('User Account');

http://sputility.codeplex.com

| improve this answer | |

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.