Auto-populate the current user's name on a people picker
-
Thursday, May 24, 2012 4:04 AM
Hello,
Is there a way to auto-populate the current user's name on a people picker by designing the list form through SPD? i know i can do it in InfoPath Designer, but i found no way to do that in SPD..
I saw someone suggested the below javascript. I used a CEWP and inserted the code, but the current user name still didn't showed up on the people picker field. I changed the fieldName to the field name of the people picker, but still didn't worked.
<script type="text/javascript">
$(document).ready(function() {
$('div.ms-inputuserfield').text($().SPServices.SPGetCurrentUser({fieldName: "Title",debug: false}));});
</script>
All Replies
-
Thursday, May 24, 2012 5:23 AM
Try the following C# code
SPUser CurrentUser = SPContext.Current.Web.CurrentUser; PickerEntity peEntity = new PickerEntity(); peEntity.Key = CurrentUser.LoginName; peEntity = peOwner.ValidateEntity(peEntity); peOwner.Entities.Add(peEntity);
where peOwner is my People Picker
--------------------------------------------------------
Surender Singh Bhadauria
My Blog- Marked As Answer by Yin Hu Gui Friday, May 25, 2012 4:01 PM
-
Thursday, May 24, 2012 6:23 AMModerator
Hi,
Try below script:
http://blogs.vbcity.com/skullcrusher/archive/2008/04/10/9024.aspx
I have not tested this yet so please tell us if it works
Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
- Marked As Answer by Yin Hu Gui Friday, May 25, 2012 4:01 PM
-
Friday, May 25, 2012 4:01 PMThanks for both of your helps! The information help a lot!
-
Friday, May 25, 2012 5:15 PM
Hi,
Did you add SPServices to your site and referenced it in your masterpage? Otherwise it will not work.
Blog: Married to SharePoint Twitter: @SPNiax
-
Tuesday, May 29, 2012 7:33 AMNo i didn't... thanks SPNiax.
-
Thursday, June 28, 2012 3:42 AM
Here's a post I wrote on a no-code way to pre-populate the people picker:
http://www.sharepoint911.com/blogs/laura/Lists/Posts/Post.aspx?ID=178
InfoPath
2010: Pre-populate the People PickerLaura Rogers
SharePoint911: SharePoint Consulting
Blog: http://www.sharepoint911.com/blogs/laura
Twitter: WonderLaura
Books:Beginning SharePoint 2010: Building Business Solutions with SharePoint
Using InfoPath 2010 with Microsoft SharePoint 2010 Step by Step

