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.
3
votes
2 Answers
4
votes
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 :)
1
votes
@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.