This project has moved and is read-only. For the latest updates, please go here.

getting values of current user through SPServices

Sep 5, 2014 at 4:59 PM
Hello ALL.

I'm on SP Server 2013 - enterprise.

I found a jquery code that gets values of current user through SPServices.
Article -

This works great for single line text fields but doesn't work for people picker fields.

I'm a bit stuck. Perhaps I'm doing something wrong. Help would be appreciated.

The .js code I'm using is below. The Field are: Employee, LastName, FirstName, Department, Office, Manager

Thanks, Larry

<script language="javascript" src="/sites/demo/SiteAssets/jquery-2.1.0.min.js" type="text/javascript"></script>
<script language="javascript" src="/sites/demo/SiteAssets/jquery.SPServices.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript"> $(document).ready(function() { //Get and Set Title var userTitle = $().SPServices.SPGetCurrentUser({ fieldName: "Title" }); $("input[Title='Employee']").val(userTitle); //Get and Set Office var userOffice = $().SPServices.SPGetCurrentUser({ fieldName: "Office" }); $("input[Title='Office']").val(userOffice); //Get and Set Department var userDepartment = $().SPServices.SPGetCurrentUser({ fieldName: "Department" }); $("input[Title='Department']").val(userDepartment); //Get and Set LastName var userLastName = $().SPServices.SPGetCurrentUser({ fieldName: "LastName" }); $("input[Title='LastName']").val(userLastName); //Get and Set FirstName var userFirstName = $().SPServices.SPGetCurrentUser({ fieldName: "FirstName" }); $("input[Title='FirstName']").val(userFirstName); //Get and Set Manager (People or Group field) var columnName = 'Manager'; var managerName; $().SPServices({ operation: "GetUserProfileByName", async: false, AccountName: $().SPServices.SPGetCurrentUser(), completefunc: function (xData, Status) { $(xData.responseXML).find("PropertyData > Name:contains('Manager')").each(function() { managerName = $(this).parent().find("Values").text(); }); } }); var searchText = RegExp("FieldName=\"" + Manager + "\"", "gi"); $("").each(function() { if(searchText.test($(this).html())) { $(this).find("div[Title='People Picker']").html(managerName); return false; } }); }); </script>
Sep 5, 2014 at 10:45 PM
It's a little hard to read your code and the link doesn't go to anything useful, but...

Which part is not working for you? I would expect that most of this would be fine.