Set SharePoint Person or Group Field (People Picker) Default Value to Current User
Requirement: In a request tracking system, wanted to auto-populate people picker value from currently logged-in User.
Solution: How to set the People Picker field value to the current user? Let’s use jQuery and SPServices to fetch the logged-in user name and fill the SharePoint list form’s people picker field value.
In short, Call SPServices function: SPGetCurrentUser() to retrieve the get the current user. Populate the people picker In SharePoint List Form using jQuery! Place this script in a text file, upload to any SharePoint library, Edit the NewForm.aspx page by appending ?toolpaneview=2 to the URL, Add a CEWP and locate the script in Content editor web part’s property.
<!-- jQuery Reference. You can refer it from Layouts Folder/Doc Library too, after uploading the script. -->
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<!-- Download SPServices from: https://sympmarc.github.io/SPServices/ Or use this CDN -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//Get the current user
var user= $().SPServices.SPGetCurrentUser();
//Set all sharepoint 2010 people picker default to current user
$("div[title='People Picker']").text(user);
});
</script>
When we have multiple people picker fields in the SharePoint form, we got to find the one needs to be set.
<!-- jQuery Reference. You can refer it from Layouts Folder/Doc Library too, after uploading the script. -->
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<!-- Download SPServices from: https://sympmarc.github.io/SPServices/ -->
<script type="text/javascript" src="https://sharepoint.crescent.com/helpdesk/support/jquery.SPServices-2013.01.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//Get the current user name
var user= $().SPServices.SPGetCurrentUser();
//Find the Specific People picker field "Requester" and set its value
$().SPServices.SPFindPeoplePicker({
peoplePickerDisplayName: "Requester",
valueToSet: user,
checkNames: true
});
});
</script>
Result in action:
Set SharePoint People Picker Default Value to Current User
How to do the same in sharepoint 2013 people picker?
thanks in advance
An idea for SPS 2013 ?
Its really g8 article…
helps a lot…