InvalidPluginExecutionExeception and Auto Save in CRM 2013 RRS feed

  • Question

  • Hello Experts,

    I have a Post update plugin which triggers and checks for a pickist attribute value on the entity and performs some operation. For a particular value of the picklist attribute I just need to rollback the operation without doing anything. For rolling back I am throwing an exception with an error message.

    The code is something as below.

    if (((OptionSetValue)(entity.Attributes["picklist"])).Value == 100000001)
       //do something here
    else if(((OptionSetValue)(entity.Attributes["picklist"])).Value == 100000002) 
    throw new InvalidPluginExecutionException(OperationStatus.Failed,"Not a valid operation for this value");

    Expectation - My expectation is that when the operation is tried with value 10000002, the error message should be prompted to the user and the update should be rolled back.

    Actual - The user is getting the error message prompt, but the form is remaining in the unsaved state. Thus, it is getting triggered after every 10 sec (auto save) and throwing the same error. The only way to get out of this loop is to refresh the browser window or to change the picklist value to 100000001 which is not what I intent.

    Anyone facing similar issue? Any workaround?



    Monday, February 24, 2014 8:31 PM

All replies

  • Your scenario looks like the expected behavior of the CRM system and how it's been working for last versions except the fact that auto save was introduced in CRM 2013.

    When there is a plugin exception throw, the error message is prompted and all the CRM processes in the same plugin transaction are rolled back at the server side but the values filled up on the form remains the same just before OnSave is triggered.

    e.g. In CRM 2011, if you have the same plugin and the user choose the picklist value 100000002 and save the form, the plugin error will be prompted, and after the user click OK in the plugin error prompt, the user will still see the picklist value selected as 100000002 since the form is not going to be refreshed.

    So, the same scenario occurs to your case and the only difference is that the Save event is triggered by Auto Save instead of initiating by the user.

    So, the workaround solution is to have those validations on client script and clear the value (or change it back to old value) if the user makes invalid selection.

    Or if your validation logic is simple enough, you can also use the Business Logic feature in CRM 2013.

    Tuesday, February 25, 2014 1:40 AM
  • Hello Swaroop,

    As suggested by Linn Zaw Win, you can look for workarounds here to implement your requirement, you can also disable auto save that should help you and even you just want to disable auto save for particular entity, Check this.


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Tuesday, February 25, 2014 2:55 AM
  • Have you considered using a synchronous workflow: Stop - Canceled - [Error message]?
    • Proposed as answer by Chris_Cohen Tuesday, February 25, 2014 4:57 PM
    Tuesday, February 25, 2014 4:56 PM
  • Hi Linn,

    Thanks for your response.

    If I remember correctly, in CRM 2011 if there is a plugin exception, on clicking OK on the prompt the whole entity page used to refresh thus removing the unsaved/changed picklist value and rolling it back to the one in the DB (before changing). --- Please correct me if I am wrong here.

    And thus I think the problem with CRM 2013 is that, the page isn't getting refreshed if the exception is hit (as everything happens in the same browser window) - keeping the picklist value unsaved on the page and in addition to this the Auto save functionality keeps triggering prompting the error message everytime.

    So looks like this is an issue with the way CRM 2013 works.

    Is there a way to refresh the entity page once the exception is hit? Or my only way out of this is to change the validations to client side?



    Thursday, February 27, 2014 11:02 PM
  • Hi Swaroop,

    In CRM 2011, sometimes, the page seems to refresh at a plugin exception but the values one the form are not rolling back.

    Anyway, it's the best to change those validations to client side for your scenario.

    I can't think of any working script to refresh the entity page once the exception is hit.

    I'm not sure it'll work but I have an idea and you may give it a try.

    At onSave of the form, prevent it from being saved if it's auto save.

    function preventAutoSave(econtext)
        var eventArgs = econtext.getEventArgs();
        if (eventArgs.getSaveMode() == 70) // AutoSave

    And call the save method in the Script, and in errorCallback, try to refresh the page.

    Xrm.Page.data.save().then(successCallback, errorCallback);

    Friday, February 28, 2014 2:06 AM