2014-09-23 521 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