locked
How do we get our plugin code to run asa a transaction? RRS feed

  • Question

  • We have a Post-operation plugin that creates a number of entities.  For some reason when the InvalidPluginExecutionException is thrown the transaction is not rolling back.  so we set a break point and discover by checking the IsInTransaction that we are not in a transaction.  How do we ensure our code is running in a transaction.  The plug in is registered as a Post-operation plugin and from what I have read transaction in these types of plugins should have IsInTransaction as true not false like we are seeing.  Is there something else that is needed to ensure the creates run as a transaction?

    John


    Thanks, John

    Thursday, May 22, 2014 2:56 PM

Answers

  • We figured out our issue.  We were run the plugin as Async.  When we changed it to Sync.  The IsInTransaction  became true and the rollback occurred as advertised.  So everyone should remember to run the plugins that need to be transactional as Sync not Async.

    John


    Thanks, John

    • Marked as answer by jbavera Thursday, May 22, 2014 4:40 PM
    Thursday, May 22, 2014 4:40 PM

All replies

  • PostOperation (stage = 40) steps should run within the transaction. Can you check the Stage property, to see if it's 40 or 50, or something else.

    For some entities the transaciton behaviour is non-standard. Activity entities are one example, as are potentially the account, contact and lead (if manipulating addresses), and the opportunity, quote, salesorder entities. Which entity is the plugin registered on ?


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Thursday, May 22, 2014 3:47 PM
    Moderator
  • We figured out our issue.  We were run the plugin as Async.  When we changed it to Sync.  The IsInTransaction  became true and the rollback occurred as advertised.  So everyone should remember to run the plugins that need to be transactional as Sync not Async.

    John


    Thanks, John

    • Marked as answer by jbavera Thursday, May 22, 2014 4:40 PM
    Thursday, May 22, 2014 4:40 PM