[英]How to get Opportunityproduct by QuoteDetail in MS Dynamics CRM?
[英]How to get current user privileges in MS Dynamics CRM on server side
我正在使用MS CRM插件,它應該能夠確定當前用戶是否具有對當前實體的寫權限。 我不知道如何完成這項任務。
似乎目前尚不支持以最用戶友好的方式完成此任務。
除了組成FetchXML查詢並解析其輸出之外,MS CRM 2011 SDK中還有其他選擇嗎?
這是我想出的—這段代碼將檢查當前用戶是否對當前記錄賦予了特權:
// Requesting user's access rights to current record
var principalAccessRequest = new RetrievePrincipalAccessRequest
{
Principal = new EntityReference("systemuser", localContext.PluginExecutionContext.UserId),
Target = new EntityReference(localContext.PluginExecutionContext.PrimaryEntityName, localContext.PluginExecutionContext.PrimaryEntityId)
};
// Response will contain AccessRights mask, like AccessRights.WriteAccess | AccessRights.ReadAccess | ...
var principalAccessResponse = (RetrievePrincipalAccessResponse)localContext.OrganizationService.Execute(principalAccessRequest);
if ((principalAccessResponse.AccessRights & AccessRights.WriteAccess) != AccessRights.None)
{
...
...
...
}
如果用戶對當前記錄具有WriteAccess
,則將執行if
語句中的代碼。
根據馬特的答案:
您只需要執行聯接並添加您關心的where子句。 這是等效的SQL:
SELECT Privilege.*
FROM Privilege
INNER JOIN RolePrivilege ON Privilege.PrivilegeId = RolePrivilege.PrivilegeId
INNER JOIN SystemUserRole ON SystemUserRole.RoleId = RolePrivileges.RoleId AND SystemUserRole.SystemUserId = (user's GUID)
-- WHERE Add whatever constraints on the Privilege entity that you need
您可以使用Fetch XML,LINQ to CRM,Query Expressions甚至OData來執行此操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.