locked
CRM 2013: Passing Account Info into Webservice via Plugin RRS feed

  • Question

  • We are using CRM 2013. I'm trying to create a plugin that triggers when a CRM Account is created. Then the plugin will fires and sends an attribute 'AccountNumber' into an external webservice. However the webservice does not seem to get called whatsoever now.

    At first I thought I had to do a PostImage, but then decided not to use it anymore. Also at first I was using "EntityMoniker" as a plugin parameter but then corrected it to type "Target".

    Here's my code:

    I'm wondering if probably the plugin is never triggered at all. Is there a way to check whether a plugin gets triggered or not?

    Could someone please guide me in the right direction?

    Thanks in advanced for your help.

    var trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    
                // The InputParameters collection contains all the data passed in the message request.
                var targetEntity = context.GetParameterCollection<Entity>(context.InputParameters, "Target");
    
                if (targetEntity == null)
                    throw new InvalidPluginExecutionException(OperationStatus.Failed, "Target Entity cannot be null");
    
                // Make sure the new Case Id is available
                if (!context.OutputParameters.Contains("id"))
                    return;
    
                var accountID = new Guid(context.OutputParameters["id"].ToString());
    
                var postImage = context.PostEntityImages["PostImage"];
    
                if (postImage == null)
                    throw new InvalidPluginExecutionException(OperationStatus.Failed, "Post Image is required");
    
                var accountNo = targetEntity.Attributes["new_accountnumber"].ToString();
    
                var service = new PropertyServiceClient("");
    
                var newProp = new PropertySetup
                {
                    _prop = new GProperty
                    {
                        _propertyNm = accountNo
                    }
                };
    
                service.CreateNewGProperty(newProp);
                service.Close();


    • Edited by triangular Tuesday, November 4, 2014 1:33 AM typo
    Tuesday, November 4, 2014 1:22 AM

Answers

All replies

  • Hi,

    The easiest way to check if the plugin is triggered is to throw a InvalidPluginExecutionException early in the code, that will be picked up and presented as a popup. Another way is doing step debugging but that's not possible in an online environment.

    How is you plugin registered?

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se


    Tuesday, November 4, 2014 9:05 AM
  • you could also build the dll in debug mode and copy the dll and pdb file into server /assembly folder to debug.

    http://msdn.microsoft.com/en-us/library/gg328574.aspx

    your plugin is best registered on create message and post operation.

    regards

    Jithesh

    • Marked as answer by triangular Thursday, November 6, 2014 9:17 PM
    Tuesday, November 4, 2014 12:05 PM
  • Thank you Rickard and Jithesh.

    I put InvalidPluginExecutionException as suggested at the very beginning in my code as below:

    public override void OnExecute(IServiceProvider serviceProvider, IPluginExecutionContext context)
            {
    
                var trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                throw new InvalidPluginExecutionException("My plugin is throwin error");
    ...
    ...
    ...}

    But the error message didn't even get thrown... which means that my plugin never gets triggered.

    I don't understand why it doesn't fire because I have registered the plugin under 'Create Account' and post operation as Jithesh mentioned.

    Could someone please guide me what else can prevent plugins from firing?

    This is the only plugin firing for the Account entity. There's no other dependency or anything that I think could block the plugin.

    Thanks much in advanced.

    ichan


    • Edited by triangular Tuesday, November 4, 2014 9:17 PM
    Tuesday, November 4, 2014 9:16 PM
  • What tool do you use to register the plugin? mine looks different. not that it really matters. I use the one from SDK.

    sometime, recycling the application pool will help you refresh the cached version of dll.

    Another option is to change the isolation mode to sandbox and back to none (if onpremise) to reflect the latest version of dll.

    Please try?

    Tuesday, November 4, 2014 9:41 PM
  • Hello Jithesh, thanks for your prompt reply.

    I use the Plugin Registration tool for CRM 2013. I think yours is 2011?

    I've always used the 'Sandbox' in registering my plugin (we are on CRM 2013 on-premise version).

    However when I change to use 'none', I got below error message:

    I'll try recycling the website shortly and will let you know the outcome. Thanks much for your input.

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Action failed for assembly '.Plugins, Version=1.0.0.1, Culture=neutral, PublicKeyToken=71924faff9160a40': Assembly must be registered in isolation.
    Detail: <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <ErrorCode>-2147220906</ErrorCode>
      <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
      <Message>Action failed for assembly 'Plugins, Version=1.0.0.1, Culture=neutral, PublicKeyToken=71924faff9160a40': Assembly must be registered in isolation.</Message>
      <Timestamp>2014-11-04T21:48:44.2926956Z</Timestamp>
      <InnerFault>
        <ErrorCode>-2147220906</ErrorCode>
        <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
        <Message>Action failed for assembly 'Plugins, Version=1.0.0.1, Culture=neutral, PublicKeyToken=71924faff9160a40': Assembly must be registered in isolation.</Message>
        <Timestamp>2014-11-04T21:48:44.2926956Z</Timestamp>
        <InnerFault i:nil="true" />
        <TraceText i:nil="true" />
      </InnerFault>
      <TraceText i:nil="true" />
    </OrganizationServiceFault>

    Server stack trace:
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       at Microsoft.Crm.Tools.Libraries.RegistrationHelper.UpdateAssembly(CrmOrganization org, String pathToAssembly, CrmPluginAssembly assembly, PluginType[] type)
       at Microsoft.Crm.Tools.AssemblyRegistration.PluginRegistrationViewModel.btnregisterClick()

    Tuesday, November 4, 2014 9:51 PM
  • Plugin registration tool version shows 6.0 for me. The error you got is because you are not a deployment manager. make yourself one and you will be able to reigister plugin outside the sandbox.

    Regards,

    Jithesh.K

    Tuesday, November 4, 2014 10:09 PM
  • Yes actually I'm already a "Deployment Administrator" on this CRM site.

    Thanks.

    Tuesday, November 4, 2014 10:26 PM
  • Strange, both that the plugin isn't triggering and that you can't register it outside the sandbox if you're deployment admin. The only time I've seen that error is when you're trying to register non-sandbox plugins without being deployment admin.

    Have you updated the assembly btw? I've found that when you chose an assembly from the list, you need to press the "load assembly" button, even if the plugins seems to be updated in the checkbox list. Worth a try.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Wednesday, November 5, 2014 8:28 AM
  • Thanks Rickard for your reply. Yes this is weird. It's actually the first plugin that I created after a while. I tried throwing the InvalidPluginExecutionException error into one plugin that we now for sure is working, and it is actually throwing the error message. For some reason it is not doing it on this one newly created plugin...

    Any support is appreciated. Thanks,

    Wednesday, November 5, 2014 7:02 PM
  • What does the code look like, if you are able to show it.

    Another thing is to create a new plugin that only throws the exception and register that. The two most common errors I've done when I have strange issues is that either the class or the execute aren't public.

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Thursday, November 6, 2014 7:39 AM
  • Thank you all for the help. Turned out the plugin was never triggered because I didn't realize it was using wrong MessageProcessingStage. It was using "BeforeMainOperationInsideTransaction" instead of "AfterMainOperationInsideTransaction"...

    Appreciate all your input!

    Thursday, November 6, 2014 9:19 PM