This project has moved. For the latest updates, please go here.

SPGetCurrentUser "Person or Group"

Jun 8, 2010 at 9:10 PM

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script language="javascript" type="text/javascript" src="/JQuery/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/JQuery/jquery.SPServices-0.5.5.min.js"></script>
<script type="text/javascript">
 $(document).ready(function() {
 var thisUser = $().SPServices.SPGetCurrentUser({
  fieldName: "Title",
  debug: true
 /*alert("UserName: " + thisUser);*/

Using the above, I can auto populate Person2 column (Single line of text) with current user name (Last, FirstName)
However it will not auto populate Person3 column (Person or Group).

Is this by design, or do I have something wrong? Alert does work with correct name.


Jun 9, 2010 at 4:14 AM

The way a Person or Group column is represented in the page is much more complex than just an INPUT control (it also has some script sitting behind it).  If you dig into the DOM, you'll see that the text representation of the user is stored in a SPAN rather than an INPUT.


Jun 9, 2010 at 12:39 PM

So is there no way to populate then? If not - no problem. If so, do you have a link for an example?

Jun 9, 2010 at 12:56 PM

With code, all things are possible. ;+)

I don't have a jQuery example handy for you, but check out this old blog post on how to do it with JavaScript:


Mar 17, 2011 at 9:42 PM

I do this 

$("nobr:contains('Username')").parents('div:first').find("[id*='UserField_upLevelDiv']").html(userNT); // Sets the login