2015-12-08 27 views
0

讀訪問他們我在的預置型動態CRM 2011的環境,我想爭取所有這些帳戶爲之用戶具有讀取權限。到目前爲止,我只是接觸到以下內容,只是通過檢查用戶是否具有ReadAcces。但是我想查詢一次並填充用戶具有讀權限的所有帳戶。檢索所有賬戶,如果用戶已經使用C#

private static bool retrieveReadAccess(IOrganizationService service, Guid userId, Guid avcId) 
    { 
     //retrieve user ReadAccess to account 
     RetrievePrincipalAccessRequest principalAccessReq = new RetrievePrincipalAccessRequest 
     { 
      Principal = new EntityReference("systemuser", userId), 
      Target = new EntityReference("account", avcId) 
     }; 
     RetrievePrincipalAccessResponse principalAccessRes = (RetrievePrincipalAccessResponse)service.Execute(principalAccessReq); 

     if (principalAccessRes.AccessRights.HasFlag(AccessRights.ReadAccess)) 
     { 
      return true; 
     } 
     return false; 
    } 

回答

0

如果你只是想某一個用戶可以讀取,使用來電顯示參數時,您對SDK調用帳戶的列表:

https://msdn.microsoft.com/en-us/library/gg309629.aspx

這將執行API調用就好像它來自該用戶一樣,只會返回用戶被允許看到的記錄。

// Retrieve the system user ID of the user to impersonate. 
OrganizationServiceContext orgContext = new OrganizationServiceContext(_serviceProxy); 
_userId = (from user in orgContext.CreateQuery<SystemUser>() 
      where user.FullName == "Kevin Cook" 
      select user.SystemUserId.Value).FirstOrDefault(); 

// To impersonate another user, set the OrganizationServiceProxy.CallerId 
// property to the ID of the other user. 
_serviceProxy.CallerId = _userId; 

// Use serviceProxy for any API calls and it will run as the above user 
+0

喬希,感謝您的回覆。讓我以其他方式重複我的問題。 我是系統管理員,我想分享的接觸只是誰擁有至少ReadAccess父帳戶的用戶。所以這是不是一個與用戶的GUID比較帳號一個,爲什麼我想要得到所有帳戶的用戶可以在一個陣列讀取,然後檢查父帳戶ID,如果它落入陣中則分享孩子接觸。 這有道理嗎? – User089

相關問題