How to get email address from multiple people picker

Jerry Xu-MSFT 7,911 Reputation points
2020-10-28T05:47:13.34+00:00

Hi,

I am using below script to get email address from multiple people picker

But the problem is I am getting the same address when I am trying to get email address from another people picker as well.

Let me know if I am making any mistake here.

var secondApproverLoginName = $("span.ms-entity-resolved").attr("title");

var processedSecondApproverEmailAddress = $("span.ms-entity-resolved").attr("ID");

var start = processedSecondApproverEmailAddress.indexOf(":");

var end = processedSecondApproverEmailAddress.indexOf("_Processed");

var secondApproverEmailAddress = processedSecondApproverEmailAddress.substring(start-1, end);

Regards,

Sudheer

Thanks & Regards, Sudheer

Source Link from TechNet

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,564 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-10-29T03:18:26.77+00:00

    The default value of $("span.ms-entity-resolved").attr("title") is the title attribute of the first element matching the selector. If there are multiple matching elements in the page, you can use each method to traverse all matching elements.
    Sample code for your reference:

      $("span.ms-entity-resolved").each(function(){  
                    var secondApproverLoginName = $(this).attr("title");              
                    var processedSecondApproverEmailAddress = $(this).attr("ID");  
                    var start = processedSecondApproverEmailAddress.indexOf(":");  
                    var end = processedSecondApproverEmailAddress.indexOf("_Processed");  
                    var secondApproverEmailAddress = processedSecondApproverEmailAddress.substring(start - 1, end);  
                    console.log(secondApproverEmailAddress)  
            })  
    

    Test Result:
    35864-image.png
    Different columns need to use different attributes in the selector to get the corresponding element.

    $("div[title='peopleColumn1'] span.ms-entity-resolved")  
    $("div[title='peopleColumn2'] span.ms-entity-resolved")  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments