Populate Current Loggedin User in People Picker


In one of my project we need populate current logged in user in People Picker by default. I have implemented below code to do it.

Add 1.7.2.jquery.min.js and jquery.SPServices-2014.02.min.js file in the master page or page level.

 
$(document).ready(function() { 
 ExecuteOrDelayUntilScriptLoaded(loadCurrentUser, "sp.js"); 
});

function loadCurrentUser() { 
 var userName = $().SPServices.SPGetCurrentUser({ fieldName: "UserName", debug: false});
 $('h3:contains("PeoplePickerFieldName")').closest('tr').find('div[title="People Picker"]').html(userName);
 $('img[title="Check Names"]').trigger('click'); 
} 

** Replace “PeoplePickerFieldName” with your people picker field name.

** Replace “userName” with your desired user’s user name to add other user in peoplepicker.

Let me know if you face any challenges.

Happy Coding.. 🙂

Regards, Jay Doshi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s