Auto Populate username in list form using JavaScript Sharepoint

1.open default new form/edit form  under edit form web parts

listedit

2.add the script editor web part on the web page.

script editor

3.click on edit snippet inside script editor webpart and add the below code

embedcode

click on insert. after click stop editing page.

now whenever you open new form it will have current user as populated in peoplepicker.

listform

<script src="/my/Style%20Library/jquery-1.11.2.js"></script>
<script language="javascript" src="/my/Style%20Library/jquery.SPServices-0.6.2.js" type="text/javascript">
</script>  
<script language="javascript" type="text/javascript"> 
$(document).ready(function() { 
var userName= $().SPServices.SPGetCurrentUser(); 
$(".sp-peoplepicker-initialHelpText.ms-helperText").text(""); 
$(".sp-peoplepicker-topLevel").val(userName); 
 $(".sp-peoplepicker-topLevel").text(userName); 
 }); 
</script> 

Note.Make sure page will have reference of jQuery.SPServices-0.6.2.js and jQuery-1.11.2.js files. you can add any where in web and add reference to a page.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s