【问题标题】:CRM 2011 Plugin ExceptionCRM 2011 插件异常
【发布时间】: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


    【解决方案1】:

    不确定为什么您没有收到错误框。一种解决方案是在更新消息上注册您的插件。 当用户分配记录时,更新消息会在分配消息之前触发。 您可以检查“目标”实体是否包含 ownerid 字段。如果它运行比较检查并抛出错误。

    HTH

    【讨论】:

      【解决方案2】:

      您是否尝试过使用 InvalidPluginExecutionException 的构造函数来接受消息和异常?

      所以代替:

      Throw New InvalidPluginExecutionException("My Message Here")
      

      类似:

      Throw New InvalidPluginExecutionException("My Message Here", new FaultException<OrganizationServiceFault>())
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多