【发布时间】:2013-11-29 03:34:18
【问题描述】:
我的插件有问题,没有显示异常(尽管它在不保存的情况下正确运行),但仅在一种情况下。这是场景:
我们有一个实体,每个业务部门只能存在一个活动实体。我有插件来检测激活、分配和创建,它们都会检查该作品的所属业务部门,如果它是重复的,则抛出异常。
这适用于创建、激活和分配WHEN通过按顶部的分配按钮或按所有者字段旁边的放大镜来调用分配。下面的图像工作。
但是,如果用户在文本框中输入新的所有者名称并选择用户,然后按保存,则分配插件会被调用,并且会阻止更改,但不会出现异常消息框。我使用了我们的内部日志系统,发现异常行被命中,但仍未显示。
Public Class OurEntityPreAssign
Implements IPlugin
Public Sub Execute(ByVal serviceProvider As System.IServiceProvider) Implements Microsoft.Xrm.Sdk.IPlugin.Execute
Dim context As IPluginExecutionContext = CType(serviceProvider.GetService(GetType(IPluginExecutionContext)), IPluginExecutionContext)
Dim factory As IOrganizationServiceFactory = CType(serviceProvider.GetService(GetType(Microsoft.Xrm.Sdk.IPluginExecutionContext)), IOrganizationServiceFactory)
Dim service As IOrganizationService = factory.CreateOrganizationService(context.UserId)
Dim entity As Entity
' Get Assignee
' Compare it to the PreImage
' If Same BUID, do nothing
' Else check for duplicate
ErrorLogUtil.WriteToFile("PreAssign") '--> This gets logged
If context.InputParameters.Contains("Assignee") AndAlso TypeOf context.InputParameters("Assignee") Is EntityReference Then
Dim assigneeER As EntityReference = CType(context.InputParameters("Assignee"), EntityReference)
entity = service.Retrieve(assigneeER.LogicalName, assigneeER.Id, New Microsoft.Xrm.Sdk.Query.ColumnSet(True))
Dim er As EntityReference = CType(entity.Attributes("businessunitid"), EntityReference)
Dim initialBusinessUnit As EntityReference = CType(context.PreEntityImages("PreImage").Attributes("owningbusinessunit"), EntityReference)
ErrorLogUtil.WriteToFile("initialBusinessUnitID:" & initialBusinessUnit.Id.ToString & ", assigneeER: " & er.Id.ToString)' -->These values are different, which means we need to check to see if the new one already has a record
If Not er.Id = initialBusinessUnit.Id Then
If Not er.Name = "Disabled Users" Then
If OurEntity.isDuplicate(er.Id, service, context.PreEntityImages("PreImage").LogicalName) Then
ErrorLogUtil.WriteToFile("ExceptionThrown") '-->This is being hit, which means that the throw call should also be hit, or some other error should appear
Throw New InvalidPluginExecutionException("My Message Here")
End If
End If
End If
End If
End Sub
End Class
很清楚,我查看了this post,它没有任何答案,这确实是一个不同的问题,因为该提问者至少收到了某种错误消息。
有没有其他人经历过这种情况?
【问题讨论】:
标签: vb.net plugins dynamics-crm-2011 dynamics-crm