Plugin to Update Quote after Activated RRS feed

  • Question

  • Hello,

    We're on CRM 2013 on-premise. I'm writing a plugin that fires when a Quote status is changed to Active. When that happens the plugin will 1) create a new custom entity and 2) update a Quote's lookup field to reference the new custom entity.

    I have read in other forum post that I have to register my SetState and SetStateDynamicEntity steps to "Pre-operation". Otherwise I will receive an error "The entity cannot be updated because it is read only" because of #2 step above.

    Now if I change the steps to "Pre-operation", it is weird that the plugin did not do anything... I put a 'InvalidPluginExecutionException' but it's entirely skipped...

    Any idea is appreciated. Thanks in advance.


    Wednesday, September 23, 2015 8:01 PM

All replies

  • Hello,

    I'm still looking for a solution for this. Here's the code that I have that simply throws 'InvalidPluginExecutionException' but the error never shows up when I change the steps to "Pre-operation"...

    var targetReference = context.GetParameterCollection<EntityReference>(context.InputParameters, "EntityMoniker");
                if (targetReference == null)
                    throw new InvalidPluginExecutionException(OperationStatus.Failed, "Target Entity cannot be null");
                var state = (OptionSetValue)context.InputParameters["State"];
                //only proceed if the Quote State is 'Active'
                if (state == null || state.Value != (int)Schema.Quote.State.Active)
                var postImage = context.PostEntityImages["PostImage"];
                if (postImage == null)
                    throw new InvalidPluginExecutionException(OperationStatus.Failed, "Post Image is required");
                var quoteId = postImage.Id;
                throw new InvalidPluginExecutionException(OperationStatus.Failed, "I did not get here");

    Any input is appreciated. Thanks,


    • Edited by triangular Thursday, September 24, 2015 6:24 PM
    Thursday, September 24, 2015 6:22 PM
  • HI Tri,

    In this case i would go for "Debug the plugin" MSDN help || Other

    Check what actually going on inside your code.

    Thursday, September 24, 2015 6:44 PM
  • Hello Triangular,

    I think your return statement is hit on retrieving the state of your quote. Try:

    var state = context.InputParameters.Properties["State"];

    Kind Regards

    Friday, September 25, 2015 6:44 AM