Auto Fill People Picker on custom Form Sharepoint 2010

Aug 9, 2012 at 5:32 PM
Im currently attempting to autofill a people picker field on a sharepoint 2010 custom newform.
at present Its not working if anyone could take a look and point out any obvious mistakes It would be appreciated.
Ive put the placeholdermain line in just to inform you where I have put the code.
and last thing my people picker field is called Current User.
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type="text/javascript" src="/ictsupport/jQuery%20Libraries/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/ictsupport/jQuery%20Libraries/jquery.SPServices-0.7.2ALPHA6.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var currentUser = $().SPServices.SPGetCurrentUser();
var contactPeoplePicker = $().findPeoplePicker({
  peoplePickerDisplayName: "Current User",
  valueToSet: currentUser
});
});
</script>
Thankyou
Aug 9, 2012 at 5:57 PM

Wow I've seen quite a few of these questions lately! Good that means I can make myself look awesome.

I assume that "Current User" is the name of the field for your people picker? In that case I would use this:

var peoplepicker = $("tr:contains('Current User'):last").find("div[title='People Picker']");
peoplepicker.html(currentUser);

Let me know if this works.

Aug 9, 2012 at 6:19 PM

Thanks for the quick reply,

Bit of a novice here, Ive tried copying that in but its not working but its probably down to me, Where exactly would I copy your code into.

If you could put your suggestion into the my code up the top I can give it a go.

 

Aug 9, 2012 at 7:16 PM

Replace

var contactPeoplePicker = $().findPeoplePicker({
  peoplePickerDisplayName: "Current User",
  valueToSet: currentUser
});

with

var peoplepicker = $("tr:contains('Current User'):last").find("div[title='People Picker']");
peoplepicker.html(currentUser);

May 22, 2014 at 2:42 PM
I've seen the reference several times on different posts but it never works for me.
Where do we see a <div> with a Title of People Picker ?
One of my people lookups is below.
Am I mixing apples and oranges?

thx

<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
    <nobr>Primary POC</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff5{$Pos}" ControlMode="New" FieldName="POC" __designer:bind="{ddwrt:DataBind('i',concat('ff5',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@POC')}"/>
<SharePoint:FieldDescription runat="server" id="ff5description{$Pos}" FieldName="POC" ControlMode="New"/>
                    </td>
                </tr>
Coordinator
Jun 2, 2014 at 1:56 PM
rungusto:

Have you looked at the SPFindPeoplePicker function?

M.