【问题标题】:Get email ID of user in SPServices在 SPServices 中获取用户的电子邮件 ID
【发布时间】:2012-11-14 13:06:48
【问题描述】:

我正在使用 SPServices(GetListItems 方法)从共享点列表中获取一些信息。该列表包含一个“人员或组”类型字段,该字段返回用户的数字 ID 和名称(显示名称),以分号分隔,例如“43#;John Doe”。 我需要该字段中所有用户的电子邮件地址(在所有返回的行中)。任何人都可以帮忙吗? 提前致谢。

【问题讨论】:

    标签: sharepoint spservices


    【解决方案1】:

    保罗你摇滚 :)

    从保罗的最后评论中,我得到了所需的东西。这是完美的。 :)

    您只需将以下内容添加到调用中

    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);
                        }
                    });
                }
            });
    

    对不起,保罗,我必须取消标记你的答案并做出这个答案:)

    【讨论】:

    • 优秀。这帮助我获得了用户的电子邮件、个人资料图片等等。太棒了。
    【解决方案2】:

    @Mujaba,

    我之前通过获取用户名并使用人员服务和 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;
                    }
                });
        }
    });
    

    保罗。

    【讨论】:

    • 感谢 Paul 的回复,这将起作用,但如果我们必须解析数百个用户,那么加载时间会太长。无论如何,我会尝试使用它。 :)
    • 好的。我不知道为什么我最初没有想到这一点。还有一个 CAML 选项,您可以将其提供给 GetListItems,以扩展响应中的用户字段。我从未使用过它,但记录在 SPServices 页面 (spservices.codeplex.com/…) 中。它是: CAMLQueryOptions: "True"
    猜你喜欢
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 2021-03-04
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    相关资源
    最近更新 更多