2013-11-15 45 views
1

我有我的插件没有显示异常显示(虽然它是正确行事,因为它不保存)的问题,但只在一种情况下。这里是场景:客户关系管理2011插件异常

我们有一个实体,每个业务单位只能存在一个这样的实体。我有插件来检测激活,分配和创建这一切都检查该片的拥有业务单位,并抛出一个例外,如果它是重复的。

这个工程上创建,在激活,并在指定WHEN分配由顶部按下指定按钮或按下旁边的所有者场放大镜调用。下面的图像工作。 Magnifying Glass Assign Button

但是,如果在文本框输入新所有者名称的用户类型和选择用户,然后按下保存,将分配插件被调用,从而防止了变化,但异常消息框不出现。我已经使用了我们的内部日志系统,并看到异常行正在被触发,但仍未显示。

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,它没有任何答案,这的确是一个不同的问题,因为提问者至少接受某种错误消息。

有没有人经历过这个?

回答

0

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

HTH

0

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

所以不是:

Throw New InvalidPluginExecutionException("My Message Here") 

类似:

Throw New InvalidPluginExecutionException("My Message Here", new FaultException<OrganizationServiceFault>()) 
相关问题