locked
Pluggin doesn't fire RRS feed

  • Question

  • CRM2013 - I have a custom entity new_originatingaccounts. On this entity I have two plugins, one for Create and one for Update. The entity has a two Option field called new_active. if this is set to NO then a workflow sets the record as deactivated. I am trying to fire a new plugin when the record is deactivated. After many hours of frustration, I have tried something simple just to get it working, but still nothing. I have been looking at lots of threads, so please be gentle if this looks completely wrong

    Code

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports Microsoft.Xrm.Sdk
    Imports System.ServiceModel
    Imports Microsoft.SqlServer
    Imports System.IO
    Imports CRM2013_Plugins.clsGlobals
    Imports Microsoft.Xrm.Sdk.Query
    Imports Microsoft.Xrm.Sdk.Messages
    Imports CRM2013_Plugins.cls_SQLFunctions
    
    Namespace OAccountsDelete
        Public Class cls_OAccounts_delete
            Implements IPlugin
    
            Public Sub Execute(serviceProvider As System.IServiceProvider) Implements Microsoft.Xrm.Sdk.IPlugin.Execute
                Dim context As IPluginExecutionContext = DirectCast(serviceProvider.GetService(GetType(IPluginExecutionContext)), IPluginExecutionContext)
                If context.InputParameters.Contains("EntityMoniker") AndAlso TypeOf context.InputParameters("EntityMoniker") Is Entity Then
    
                    Dim entity As Entity = DirectCast(context.InputParameters("EntityMoniker"), Entity)
                    If entity.LogicalName = "new_originatingaccounts".ToLower() Then
                        Throw New InvalidPluginExecutionException("You are not authorized to set this record as inactive")
                    End If
                End If
            End Sub
        End Class
    End Namespace

    crm tool


    Dont ask me .. i dont know

    Saturday, January 4, 2014 4:04 PM

Answers

  • Hi,
    if I remember right EntityMoniker is an EntityReference, so not an Entity, so you need to change your code as for example:

                If context.InputParameters.Contains("EntityMoniker") And Also TypeOf context.InputParameters("EntityMoniker") Is EntityReference Then
    
                    Dim entity As EntityReference = DirectCast(context.InputParameters("EntityMoniker"), EntityReference)

    and you need to register the plugin also on the SetState message.



    My blog: www.crmanswers.net - Rockstar 365 Profile

    Saturday, January 4, 2014 8:01 PM

All replies

  • Hi,

    Have you tried to deactivate the record manually (I mean without workflow)? Did it work normally in this condition? If so, I think it could be because the execution context. Register your plugin in Async mode to see if resolves your issue.

    Saturday, January 4, 2014 6:56 PM
    Moderator
  • Hi,

    I have just tried de-activating the workflow and manually deactivating the record manually. Still the plugin hasn't fired. I tried registering in async and sync but that hasn't made any difference


    Dont ask me .. i dont know

    Saturday, January 4, 2014 7:30 PM
  • Hi,
    if I remember right EntityMoniker is an EntityReference, so not an Entity, so you need to change your code as for example:

                If context.InputParameters.Contains("EntityMoniker") And Also TypeOf context.InputParameters("EntityMoniker") Is EntityReference Then
    
                    Dim entity As EntityReference = DirectCast(context.InputParameters("EntityMoniker"), EntityReference)

    and you need to register the plugin also on the SetState message.



    My blog: www.crmanswers.net - Rockstar 365 Profile

    Saturday, January 4, 2014 8:01 PM
  • Brilliant!  

    Thank you


    Dont ask me .. i dont know

    Saturday, January 4, 2014 8:09 PM