Set a SharePoint people field with jQuery

November 14th, 2011 | Posted by Marijn in code | jquery / javascript

When I talked about how to update fields in SharePoint, I was talking about the easy stuff: input fields and stuff. Now, I wanted to update / set a SharePoint people field on my form.
I did some googling and found a solution by Marc D. Anderson (in my opinion he is THE authority on sharepoint jQuery 😉 ) but I couldn’t get that to work here.

I also found a really easy solution by Dave Cavins who uses the class to define the people picker. Only bad thing with this solution is that it updates all people pickers:

Combined with SPServices it gives the following result to automatically fill in the current user:

<script type="text/javascript">
$(document).ready(function() {
   $('div.ms-inputuserfield').text($().SPServices.SPGetCurrentUser({fieldName: "Title",debug: false}));
});
</script>

In the mean time, a far better solution has arisen (like the comment from Marc says) that allows you to address a specific SharePoint people field with the help of the almighty SPServices:

</pre>
$().SPFindPeoplePicker({

peoplePickerDisplayName: "",
valueToSet: "",
checkNames: true
});

This code allows you to set a SharePoint people field by pointing to its name, add the value you want it to be and if you want it “checked”.

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

5 Responses



Leave a Reply

%d bloggers like this: