我有一个插件,可以在事件实体的更新中触发。它在另一个表(new_documentaccess)中创建一个新记录。此new_documentaccess记录需要与Incident实体具有相同的所有者。
现在,我知道我不能通过执行简单的赋值来设置所有者字段,就像实体上的任何其他字段一样。
所以,我在下面写道。
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,type = 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;
}
如果我只是使用前端以User身份运行它,我会收到以下错误。
退出PluginPreIncidentUpdate.Execute(),相关ID:4e7e4c3c-3cef-46ab-8d08-a6d0dbca34c7,发起用户:be179876-9b39-e411-80bb-000c2908bc67
问题
我应该更改哪些代码,以便即使它出错也是如此
在上面提到的错误中,ErrorDetails.txt捕获了
错误Principal user (Id=e9e3a98d-a93e-e411-80bc-000c2908bc67, type=8) is missing prvAssignnew_documentsaccess privilege
(Id=7ecaf3da-77c8-4ee3-9b29-e5a4455cd952)
?
为什么不会发生这种情况?
答案 0 :(得分:1)
首先:回答你的问题:
跟踪日志仅包含在InvalidPluginExecutionException中。你正在使用你的第二个catch并抛出被捕获的异常而不是“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记录具有assign特权的安全角色?