2012-11-14 112 views
3

我正在使用SPServices(GetListItems方法)從分享點列表中獲取一些信息。該列表包含一個「人員或組」類型字段,它返回用戶分隔符號「43#; John Doe」的數字ID和名稱(顯示名稱)。 我需要此字段中所有用戶的電子郵件地址(在所有返回的行中)。誰能幫忙? 在此先感謝。在SPServices中獲取用戶的電子郵件地址

回答

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

對不起保羅我必須取消標記您接聽和撥打這一個回答:)

+0

非常好。這有助於我獲得用戶的電子郵件,個人資料圖片等等。真棒。 – Rothrock

1

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

保羅。

+0

感謝保羅的迴應,這將工作,但如果我們必須解析數百個用戶,那麼加載將需要很長時間。無論如何,我會嘗試使用這個。 :) –

+0

好的。我不知道爲什麼我最初沒有想到這一點。還有一個CAML opiton,您可以將其提供給GetListItems,以便擴展用戶關於響應的內容。我從未使用過它,但在SPServices頁面(http://spservices.codeplex.com/wikipage?title=GetListItems&referringTitle=Lists)中有記錄。它是:CAMLQueryOptions:「 True」 –

相關問題