我有我的插件沒有顯示異常顯示(雖然它是正確行事,因爲它不保存)的問題,但只在一種情況下。這裏是場景:客戶關係管理2011插件異常
我們有一個實體,每個業務單位只能存在一個這樣的實體。我有插件來檢測激活,分配和創建這一切都檢查該片的擁有業務單位,並拋出一個例外,如果它是重複的。
這個工程上創建,在激活,並在指定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,它沒有任何答案,這的確是一個不同的問題,因爲提問者至少接受某種錯誤消息。
有沒有人經歷過這個?