I'm new to SP, please be patient with me.

Does anybody know how to auto populate 4 person fields in SharePoint with value from existing item correctly using javascript/jQuery?

What I am trying to do: based on chosen look up value fill in the fields with values from existing (chosen) item - 4 person fields (multi-person fields). The look up contains IDs of existing items. I've found following (sources), but I am not able to make it works not even for one field (error: "Uncaught TypeError: Cannot read property 'get_lookupValue' of null" appears and when I delete the .getlooupValue() then alert displays id+Email e.g. 123JohnDoe@johndoe.com).


My 'code' below.

$(document).ready(function () {
  var lookUp = $("select[title='LookUp']");
    lookUp.change(function () {

var ListItem;
function Populate() {
    var chooseLookUp = $("select[title='LookUp']").val();
    var clientContext = new SP.ClientContext.get_current();
    var chooseLookUpList = clientContext.get_web().get_lists().getByTitle('MyListName');
    ListItem = chooseLookUpList.getItemById(chooseLookUp);

function GetSet(sender, args) {
    //get-set single, multiple line text field, drop-down list, radio button
    $("input[id^='Radios'][type='radio'][value='" +  ListItem.get_item("Radios") + "']").prop('checked', true);

    //people picker for person1  
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var person1 = web.ensureUser(ListItem.get_item("Person1").get_lookupValue());
    // Get - Set People Field
    var form = $("table[class='ms-formtable']");
    var person1Field = form.find("input[id$=Person1ID_$ClientPeoplePicker_EditorInput']").get(0);
    var peoplepicker1 = SPClientPeoplePicker.PickerObjectFromSubElement(person1Field); 
    // clear people Picker
    while (peoplepicker1.TotalUserCount > 0) {
    // Set the People field
    var loginName = person1.get_loginName();
    peoplepicker1.AddUserKeys(loginName);},function(sender,args){ // on error

Many thanks

Your Answer

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

Browse other questions tagged or ask your own question.