none
Get People Picker value(Email ID) on SharePoint Online Edit Form

    Question

  • Hello,

    I want to capture Email ID from one of the people picker on List Edit Form. I have tried below function but it returns Null. Any help on this is appreciated.

    var _PeoplePicker = $("div[title='" + fieldName + "']");
    var _PeoplePickerTopId = _PeoplePicker.attr('id');
    var ppkApproverName=  getPickerInputElement(_PeoplePickerTopId); 
    											
    //common function to validate people picker filed
     function getPickerInputElement(identifier) 
       {  
    	var span; 
          var tags = document.getElementsByTagName('DIV');   
          for (var i=0; i < tags.length; i++) 
          {       
           var tempString = tags[i].id;           
           if ((tempString.indexOf('UserField_upLevelDiv') > 0))
        {   
            if(identifier == tempString)
           { 
           var innerSpans = tags[i].getElementsByTagName("SPAN");     
             for(var j=0; j < innerSpans.length; j++) 
              {   
               if(innerSpans[j].id == 'content') 
                 {   
                  return innerSpans[j].innerHTML;  
                 } 
              }  
    	 
           }     
           }   
          }   
          return null;   
       } 
       

    Friday, April 7, 2017 6:31 AM

All replies

  • Hi,

    Try this:

     

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.min.js"></script>
        <script type="text/javascript">
            $(function () {
                var fieldName = "PeoplePicker";
                var _PeoplePicker = $("div[title='" + fieldName + "']");
                var email = getPickerInputElement(_PeoplePicker);
            })        
    
            //common function to validate people picker filed
            function getPickerInputElement(_PeoplePicker) {
                var emailSpan = $(_PeoplePicker).find('.sp-peoplepicker-userSpan');
                if (emailSpan.length > 0) {
                    var _sid = $(emailSpan).attr('sid');
                    alert(_sid.split("|")[2]);
                    //return here;
                } else {
                    alert("null");
                    // return null;
                }
                
               
            }
        </script>

    Best Regards,

    Lee


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

    Monday, April 10, 2017 2:12 AM
  • This always returns null.
    Monday, April 10, 2017 6:57 AM
  • Hi,

    You need update the fieldName to your people picker field name, and you could debug the code step by step(my sample code get email from the sid of HTML tag <span class="sp-peoplepicker-userSpan" id="PeoplePicker_e654eb06-df4e-4b0c-8758-2c2dc0fef4af_$ClientPeoplePicker_i:0#.f|membership|lee_li@xxx.onmicrosoft.com_ProcessedUser0" sid="i:0#.f|membership|lee_li@xxx.onmicrosoft.com" resolveduser="true" data-sp-peoplepickerprocesseduser="true">).

    How to debug JavaScript by IE developer tool.

    https://msdn.microsoft.com/en-us/library/gg699336(v=vs.85).aspx

    Best Regards,

    Lee


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

    Monday, April 10, 2017 7:12 AM
  • Hi,

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

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

    You can also share your own solution here and mark it as answer, and we can learn from each other.

    Best Regards,

    Lee


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

    Tuesday, April 25, 2017 5:10 AM