我正在使用SPServices(GetListItems方法)从sharepoint列表中获取一些信息。该列表包含“人员或组”类型字段,该字段返回用分号分隔的用户的数字ID和名称(显示名称),如“43#; John Doe”。 我需要此字段中所有用户的电子邮件地址(返回的所有行)。有人可以帮忙吗? 提前谢谢。
答案 0 :(得分:3)
从保罗的最后评论中我得到了必要的东西。这是完美的。 :)
您唯一需要的是在呼叫中添加以下内容
CAMLQueryOptions: "<QueryOptions><ExpandUserField>True</ExpandUserField></QueryOptions>",
所以我的示例调用就变成了这个
$().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);
}
});
}
});
对不起保罗我必须取消标记你回答并做出这一回答:)
答案 1 :(得分:1)
@Mujaba,
我之前通过使用用户名并使用People服务和SearchPrincipals方法搜索它来完成此操作...以下是一个示例:
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;
}
});
}
});
保罗。