Set a People Picker’s Value on a Form

0 minute read

Following up on my recent post about getting the current value of a People Picker on a form, today I built the JavaScript to set the value, and here it is. As usual, I’ve left in my debugging code in case you want to see how it works.

// setPickerInputElement: Set a People Picker's value using its identifier to find it in the page
// Arguments:
//                            identifier:            The identifier for the instance of the fieldName (ff1, ff2, etc.)
//                            value:                    Set the fieldName to this value

function setPickerInputElement(identifier, value) {
  var tags = document.getElementsByTagName('DIV');

  for (var i=0; i < tags.length; i++) {
    var tempString = tags&#91;i&#93;.id;
    //alert('tags&#91;' + i + '&#93;.id = ' + tempString);
    if ((tempString.indexOf(identifier) > 0) && (tempString.indexOf('UserField_upLevelDiv') > 0)){
      //alert('HIT for ' + identifier + ' id=' + tags[i].id + ' value=' + tags[i].value);
      tags[i].innerHTML = value;


  1. I have a requirement wherein i need to set the choices for a Multilookup field on a Sharepoint form where in the values will be coming from another list.

    The choices will be depending on the value of the Start Date and End Date fields. My initial idea was to use a jQuery script to send a CAML Query to the source list retrieve the results (in this requirement the user names) and put them as the lookup choices. Is this feasible?

    • Jojo:

      I’d use a Lookup column which simply pulls all of the values (the default SharePoint behavior). Then in the script on the page, build the logic you need with jQuery and GetListItems. Take a look at how SPCascadeDropdowns in SPServices works for ideas.


  2. You can do it quick with jquery (tested in SP2010)

    $(“nobr:contains(‘FieldNameHere’)”).parents(‘div:first’).find(“[id*=’UserField_upLevelDiv’]”).html(ValueHere); // Sets the login

  3. Marc,

    Noob question: You often use this argument in People Picker functions “// Find a People Picker’s value using its identifier (ff1, ff2, etc.)to find it in the page ”

    I don’t quite understand how to find a the proper identifier value — though I can usually find the first People Picker on a page — What does the “ff1, ff2” indicate? Is the argument a number, text, or what?

    In advance, thanks, and sorry for the noob question!

    • Ben:

      When you create a custom form, SharePoint adds prefixes to the id of each element in the form, so they look something like:
      In OOB forms, the ids look something like this:
      Regardless, you need some way to find the element in the DOM. In my examples, I’m searching for some part of the id, often ffn, where n=1,2,3, etc.



Have a thought or opinion?