locked
How to populate current login user and display into People picker field with auto resolve ? RRS feed

  • Question

  • Hi All,

    I am using Office 365. I want to populate the current login user and display into People Picker field with "auto resolve" name  in NewForm.aspx list so that multiple users with same name does not effect.

    I have seen many post, all are using SPService and I also tried SPService. But when page load  getting error 'SPServices' is null or not an object'

    I have registered the SPService properly and Jquery also. Below is my code.

    <script type="text/javascript" src="../../SiteAssets/jquery-1.8.3.min.js"></script>

    <script type="text/javascript" src="https://partner.Expense/sites/TotalExpense/Style%20Library/jquery.SPServices-2013.01.min.js"></script>

     

    <script type="text/javascript">
    $(document).ready(function() {
      //Get the current user name
      var userName = $().SPServices.SPGetCurrentUser();
      alert ('ok');
       //Find the Specific People picker field "Requester" and set its value
       $().SPServices.SPFindPeoplePicker({
       peoplePickerDisplayName: "Requester Name",
       valueToSet: user,
       checkNames: true
      });

      });
    </script>

    Is any specific version of SPService to register for office 365?

    Error is throwing in first line : -  var userName = $().SPServices.SPGetCurrentUser();

    Please help me in this.

    Regards,

    Thursday, July 2, 2015 11:50 AM

Answers

  • Hi,

    As I understand, you want to populate the current login user and display into People Picker field with "auto resolve" name in NewForm.aspx in SharePoint online.

    From the error, it indicates the jquery.SPServices-2013.01.min.js is not loaded in the script. You could check if the path of the jquery.SPServices-2013.01.min.js is right.

    The code below can get the current user and set the value of the people picker as the current user. You should change people picker title to yours.

    <script type="text/javascript" src="="https://code.jquery.com/jquery-1.10.2.min.js"></script>
    
    <script type="text/javascript" src="https://o365e3w15.sharepoint.com/subsite1/Shared%20Documents/jquery.SPServices-2014.02.min"></script> 
    
    <script type="text/javascript">
    
      $(document).ready(function() {
    
       //Get the current user name
    
       var userName = $().SPServices.SPGetCurrentUser();
    
         var ppDiv = $("[id$='ClientPeoplePicker'][title='people1']");
    
            var ppEditor = ppDiv.find("[title='people1']");
    
            var spPP = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv[0].id];
    
            ppEditor.val(userName);
    
            spPP.AddUnresolvedUserFromEditor(true);
    
       });
    
     </script>
    

    Best regards,

    Sara Fan


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.


    • Edited by Sara Fan Friday, July 3, 2015 8:28 AM
    • Proposed as answer by Victoria Xia Thursday, July 9, 2015 12:38 AM
    • Marked as answer by Victoria Xia Friday, July 10, 2015 1:02 AM
    Friday, July 3, 2015 7:28 AM

All replies

  • Hi,

    As I understand, you want to populate the current login user and display into People Picker field with "auto resolve" name in NewForm.aspx in SharePoint online.

    From the error, it indicates the jquery.SPServices-2013.01.min.js is not loaded in the script. You could check if the path of the jquery.SPServices-2013.01.min.js is right.

    The code below can get the current user and set the value of the people picker as the current user. You should change people picker title to yours.

    <script type="text/javascript" src="="https://code.jquery.com/jquery-1.10.2.min.js"></script>
    
    <script type="text/javascript" src="https://o365e3w15.sharepoint.com/subsite1/Shared%20Documents/jquery.SPServices-2014.02.min"></script> 
    
    <script type="text/javascript">
    
      $(document).ready(function() {
    
       //Get the current user name
    
       var userName = $().SPServices.SPGetCurrentUser();
    
         var ppDiv = $("[id$='ClientPeoplePicker'][title='people1']");
    
            var ppEditor = ppDiv.find("[title='people1']");
    
            var spPP = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv[0].id];
    
            ppEditor.val(userName);
    
            spPP.AddUnresolvedUserFromEditor(true);
    
       });
    
     </script>
    

    Best regards,

    Sara Fan


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.


    • Edited by Sara Fan Friday, July 3, 2015 8:28 AM
    • Proposed as answer by Victoria Xia Thursday, July 9, 2015 12:38 AM
    • Marked as answer by Victoria Xia Friday, July 10, 2015 1:02 AM
    Friday, July 3, 2015 7:28 AM
  • Thanks , it worked for me had to make a minor change

    var ppEditor = ppDiv.find("[title^='people1']");

    Tuesday, December 27, 2016 6:44 PM