Determine Email of the person in the people field using JSOM or REST API

Hi,I have to build below HTML dynamically. The source to build this is a sharepoint list that has a people field in it.Can I use JSOM or REST API to do this? if so, can anyone help with some examples?<a href='mailto:[email protected],[email protected]'>Write email</a>
techie

Hi,
The following code for your reference:
<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var array=new Array();
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('CustomList')/items?$select=EmployeeId";
// execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
success: function (data) {
var dataResults = data.d.results;
for(var i=0;i<dataResults.length;i++){
if(dataResults[i].EmployeeId!=null){
for(var j=0;j<dataResults[i].EmployeeId.results.length;j++){
array.push(dataResults[i].EmployeeId.results[j]);
//remove the duplicated id
var employeeIds=$.unique(array);
//get the employee email by user id
var emails=getEmailsByIDs(employeeIds);
//add to send mail div
$("#SendMail").append("<a href='mailto:"+emails+"'>Send Email</a>");
error: function () {
//console.log("Failed to get details");
function getEmailsByIDs(employeeIds){
var emails=new Array();
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers?$select=Id,Email";
// execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
async: false,
success: function (data) {
var dataResults=data.d.results;
for(var i=0;i<dataResults.length;i++){
for(var j=0;j<employeeIds.length;j++){
if(dataResults[i].Id!=null&&dataResults[i].Id==employeeIds[j]&&dataResults[i].Email!=null){
emails.push(dataResults[i].Email);
error: function () {
//console.log("Failed to get details");
return emails;
</script>
<div id="SendMail">
</div>
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected].
Dennis Guo
TechNet Community Support

Similar Messages

Maybe you are looking for

  • Facebook Notifications on Hub don't appear

    I updated my Z10 recently with os 10.1. After the update, I noticed that Facebook notifications dont appear in the hub like they used to. I tried performing a system restore to the extent of losing all my contacts in full hope of it solving the probl

  • Home Movies over Apple TV

    Greetings: I have a significant amount of home movies on my windows computer in AVI format.  I want to save a copy of all AVI files.  I also have Quicktime Pro. What is the most efficient (space saving with best resolution) way of playing the AVI mov

  • Can't view the applet in the browser

    I have created an applet form using JDeveloper 3.1 to connect to the Oracle8i Rel2. However the following error appear during the connection: cannot instantiate class:oracle.jbo.common.jboInitialContextFactory Please assist.

  • UI Defaults in column properties

    Hi ! At column level, there are UI Defaults properties (label, display as,...). Apart from the fact that they exist, does DM uses these properties? if so, in which feature ? Thanks regards Fabrice.

  • Make to order Scenario...any client level settings

    Hi please guide me as there any settings which are  at Client level or company code level..... shailesh