Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Sharepoint online - prefill list field with current user (using spservices)

$
0
0

I have a form on witch I have a peoplepicker field. I want to prefill this field with the current user. To do so I use his javascript:

script src="https://blabla.sharepoint.com/scripts/jquery-2.1.4.min.js" type="text/javascript"></script><script src="https://blabla.sharepoint.com/scripts/jquery.SPServices.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">
$(document).ready(function() {
       var userName = $().SPServices.SPGetCurrentUser({
		fieldName: "Name"
	});
	$("input[Title='Userfield']").val(userName);
});</script>

Basically this works fine. The listfield "Userfield" in the newform.aspx is prefilled. The current username is there but I have to manually set focus on the "Userfield" and kind of activate the input in order to really prefill the field. If I do not "go" to the "Userfield" but immediately save the form, the field is not saved. Seems like the peoplepicker has to be activated in order to really pick a person.

I think I really need the field to be a peoplepicker field because I need to be able o calculate and filter on this field, later on.

Can someone help me out?

Thanks, Mike


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>