I am using SPServices (GetListItems method) to fetch some information from a sharepoint list. The list contains a "People or Group" type field which returns a numeric id and name(Display name) of the user separated by semi-colon like this "43#;John Doe". I need the email addresses of all the users in this field (in all the rows returned). Can anyone help? Thanks in advance.
Asked
Active
Viewed 8,245 times
2 Answers
4
Paul you rock :)
From Paul's last comment I got the required thing. Its perfect. :)
Only thing you need is to add the following to the call
CAMLQueryOptions: "<QueryOptions><ExpandUserField>True</ExpandUserField></QueryOptions>",
SO my example call becomes this
$().SPServices({ operation: "GetListItems", async: false, listName: "Assignees", webURL: "https://col.wow.telenor.com/sites/go/",
CAMLViewFields: "<ViewFields Properties='True'/>",
CAMLQuery: "",
CAMLQueryOptions: "<QueryOptions><ExpandUserField>True</ExpandUserField></QueryOptions>",
completefunc: function (xData,Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
try {
//ows_Name1 is a field of type "People or Group" the after adding CAMLQueryOptions this field returns all the fields
// propeties of user i.e. Displayname,ID,email id, domain login, sip ID etc all separate by #
var title = $(this).attr("ows_Name1");
// Splitting the resultant string with # give you string array of all the properties. In my case email ID is at
// index 3.
var userEmail = userText.split('#')[3];
// Below line is added to remove the trailing "," from email id
userEmail = userEmail.substring(0,userEmail.indexOf(','));
}
catch (e) {
alert('Exception: ' + e.message);
}
});
}
});
Sorry Paul I have to unmark you answer and make this one answer :)

Mujtaba Hassan
- 2,495
- 2
- 20
- 29
-
Excellent. This helped me get the user's email, profile picture, and so much more. Awesome. – Rothrock May 15 '15 at 17:57
1
@Mujaba ,
I have done this before by taking the User Name and doing a search for it using the People service and the SearchPrincipals method... Here is an example:
var userEmail = '';
var userId = '43';
$().SPServices({
operation: "SearchPrincipals",
searchText: "John Doe",
async: true,
completefunc: function(xData, status){
$(xData.responseXML).find("PrincipalInfo")
.each(function(){
var thisUser = $(this);
if ($.trim(thisUser.find("UserInfoID").text()) == userId) {
userEmail = $.trim(thisUser.find("Email").text());
alert("User's email: " + userEmail);
return false;
}
});
}
});
Paul.

Paul T.
- 608
- 1
- 6
- 11
-
Thanks Paul for the response, this will work but if we have to parse hundreds of users then it will take too long to load. Anyhow I'll try using this. :) – Mujtaba Hassan Nov 19 '12 at 07:31
-
Ok. I dont know why I did not think of this initially. There is also a CAML opiton that you can give to GetListItems that is suppose to expand the user fielfds on the response. I have never used it, but is documented in the SPServices page (http://spservices.codeplex.com/wikipage?title=GetListItems&referringTitle=Lists). It is: CAMLQueryOptions: "
" – Paul T. Nov 19 '12 at 12:35True