2014-09-23 522 views
0

我有一個插件,它觸發事件實體的更新。它在另一個表(new_documentaccess)中創建一個新記錄。這個new_documentaccess記錄需要具有與事件實體相同的所有者。由於安全角色導致的CRM 2013異常處理

現在,我明白我不能像實體上的任何其他字段一樣通過執行簡單賦值來設置Owner字段。

所以,我在下面寫道。

public void CreateDocumentAccess(Incident incident) 
{ 
    new_documentsaccess documentAccess = new new_documentsaccess(); 
    documentAccess.new_CaseId = incident.ToEntityReference(); 
    documentAccess.new_name = incident.OwnerId.Name; 

    Guid recordId = crmService.Create(documentAccess); 
    var request = new AssignRequest{ 
      Assignee = new EntityReference(SystemUser.EntityLogicalName, incident.OwnerId.Id), 
      Target = new EntityReference(new_documentsaccess.EntityLogicalName, recordId)}; 
    crmService.Execute(request); 
} 

但是,我得到了執行過程中出現以下錯誤,當我與

歇調試時拋出的異常時:啓用公共語言運行時異常。

拋出在行

var request = new AssignRequest{ 
      Assignee = new EntityReference(SystemUser.EntityLogicalName, incident.OwnerId.Id), 
      Target = new EntityReference(new_documentsaccess.EntityLogicalName, recordId)}; 

主體用戶(ID = e9e3a98d-a93e-e411-80bc-000c2908bc67,類型= 8)是 丟失prvAssignnew_documentsaccess特權 (ID = 7ecaf3da-77c8 -4ee3-9b29-e5a4455cd952)「}

我的插件代碼如下

try 
{ 
    CreateDocumentAccess(Incident incident); 
} 
catch (FaultException<OrganizationServiceFault> ex) 
{ 
throw new InvalidPluginExecutionException("An error occurred while creating the document access.", ex); 
} 
catch (Exception ex) 
{ 
    TracingService.Trace("ExecutePreIncidentUpdate: {0}", ex.ToString()); 
    throw; 
} 

如果我只是使用前端運行它作爲用戶,我得到以下錯誤。

退出PluginPreIncidentUpdate.Execute(),相關性id:4e7e4c3c-3cef-46ab-8d08-a6d0dbca34c7,發起用戶:be179876-9b39-e411-80bb-000c2908bc67

問題

  1. 我應該進行哪些代碼更改,以便即使在出現上述錯誤時出錯 ,ErrorDetails.txt也會捕獲 錯誤Principal user (Id=e9e3a98d-a93e-e411-80bc-000c2908bc67, type=8) is missing prvAssignnew_documentsaccess privilege (Id=7ecaf3da-77c8-4ee3-9b29-e5a4455cd952)

  2. 爲什麼它不會發生?

+0

你能發佈更多正在下載的ErrorDetails.txt文件嗎?文件頂部的XML是什麼? – Nicknow 2014-09-24 02:01:26

回答

1

首先:要回答你的問題:
跟蹤日誌只包含InvalidPluginExecutionException。你的第二個捕捉正在使用,並拋出捕獲的異常不是一個「InvalidPluginExecutionException」

更改此:

catch (Exception ex) 
{ 
    TracingService.Trace("ExecutePreIncidentUpdate: {0}", ex.ToString()); 
    throw; 
} 

爲了這樣的事情應該拉你的跟蹤記錄通過進入ErrorDetails附件。

catch (Exception ex) 
{ 
    TracingService.Trace("ExecutePreIncidentUpdate: {0}", ex.ToString()); 
    throw new InvalidPluginExecutionException("An error has occurred"); 
} 

其次:原因
你所得到的指示是,用戶沒有權限來分配new_documentaccess記錄錯誤。

當你註冊一個插件並添加一個新的步驟;您可以選擇要使用哪個用戶的上下文。 默認情況下,它設置爲「呼叫用戶」。

您能否確認調用用戶是否具有對new_documentaccess記錄具有賦值權限的安全角色?

+0

謝謝,是的。我找出原因。 – Kanini 2014-09-24 17:11:14