none
How to auto-populate current logged in user name in new item form

    Question

  • Hello Everyone,

    I am trying to auto-populate current logged in user name in "Assigned To" people picker field on the New item form (Task List). I have created below script for it. If you notice, I have commented "SPUtility.GetSPField" method and it is also working fine when I uncomment it. My problem is that this code is only working in Internet Explorer. When I open it in Chrome or Mozilla, its not working. Could you please help me to understand that what's am I missing?

    <script language="javascript" type="text/javascript" src="https://sharepoint.com/sites/SharePoint/SiteAssets/jquery-3.1.1.min.js"></script>
    <script language="javascript" type="text/javascript" src="https://sharepoint.com/sites/SharePoint/SiteAssets/jquery.SPServices-
    2014.02.min.js"></script>
    <script language="javascript" type="text/javascript" src="https://sharepoint.com/sites/SharePoint/SiteAssets/sputility.js"></script>
    
    <script language="javascript" type="text/javascript">
    $(document).ready(function() {
    //SPUtility.GetSPField('Assigned To').MakeReadOnly();
    //Current user
    var currentuser= $().SPServices.SPGetCurrentUser();
    
    var controlName = "Assigned To";
    var peoplePickerDiv = $("[id$='ClientPeoplePicker'][title='" + controlName + "']");
    var peoplePickerEditor = peoplePickerDiv.find("[title='" + controlName + "']");
    var spPeoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[peoplePickerDiv[0].id];
    
    peoplePickerEditor.val(currentuser);
    
    //SPUtility.GetSPField('Assigned To').SetValue(currentuser);
    //peoplePickerEditor.attr('value',currentuser);
    spPeoplePicker.AddUnresolvedUserFromEditor(true);
    spPeoplePicker.SetEnabledState(false);
    
    $('.sp-peoplepicker-delImage').css('display','none');
    
    });
    </script>

    Thank you.

    Saurabh



    • Edited by Saurabh Kumar Singh Wednesday, March 15, 2017 2:49 AM Including screenshot from Internet Explorer
    Wednesday, March 15, 2017 2:39 AM

All replies

  • Hi Saurabh,

    I recommend to add console.log() code under each line of the script and then debug the script in Chrome and Firefox to see where it would show the error.

    Best Regards,

    Victoria


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

    Monday, March 20, 2017 11:27 AM
    Moderator
  • Hi Saurabh,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    Best Regards,

    Victoria


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

    Thursday, March 23, 2017 3:26 AM
    Moderator
  • Hello Victoria,

    Thank you a lot for your response and suggestion.

    I am looking to debug the script as per your suggestion. Please allow me a few more days to debug and I'd confirm you back, in case I face any challenges there.

    Thank you again!

    Saurabh

    Thursday, March 23, 2017 7:49 PM
  • Hi Saurabh,

    How is everything going? Is there any update about this issue?

    Best Regards,

    Victoria


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

    Tuesday, March 28, 2017 4:28 AM
    Moderator