I am having issues with my plugins not displaying exceptions that are shown (though it is acting correctly in that it is not saving), but only in one situation. Here is the scenario:
We have an entity, and there can only exist one active of these per business unit. I have plugins to detect activate, assign and create which all check the owning business unit of the piece and throw an exception if it is a duplicate.
This works on create, on activate, and on Assign WHEN assign is called by pressing the assign button at the top or pressing the magnifying glass next to the owner field. The images below work.
However, if a user types in the new owner name in the textbox and selects a user, then presses save, the assign plugin gets called, and the change is prevented, but the exception message box does not appear. I have used our internal logging system and seen that the exception line is being hit, but still not displayed.
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
Just so it's clear, I HAVE looked at this post and it does not have any answers and it is indeed a different issue because that asker is receiving some sort of error message at least.
Has anybody else ever experienced this?