Set User into a SharePoint Person or group Field

function BindPeoplePicker(userEmail, PickerTitle)
{
   
    $('input[title="' + PickerTitle + '"]').val(userEmail).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];

    var usersobject = peoplePicker.GetAllUserInfo();
    usersobject.forEach(function (index) {
        peoplePicker.DeleteProcessedUser(usersobject[index]);
    });

    // Resolve the user using the value set in the input field.
    peoplePicker.AddUnresolvedUserFromEditor(true);
}

usage
BindPeoplePicker('anilkumar.d@vertxxx.com', 'PersonorGroupFieldTitle');

Comments

Popular posts from this blog

My Interview Experience

React Checkbox Control SPFx