locked
How change value of entity attribute back to original value after a plugin exception? RRS feed

  • Question

  • Hi,

    I have a attribute ("log_convertleadflag") that are set when the CRM user push a ribbon button:

    This execute a post-Update plugin step, were this attribute decides witch code blocks to execute.
    But: If something in the Update-code goes wrong (exception are thrown), I need to clear "log_convertleadflag" back to orginal value.

    I tried to do this by have a try-catch for the whole Update code, but I doesn't seem to be the right solution:

    Anyone have a idea how to achieve this?

    regards,

    Marius H. Enerud

    Saturday, January 14, 2017 7:27 PM

Answers

  • Ahh!! I finally solved it:

    I used "Ribbon Workbench 2016", customized the native Save-button and made a new JavaScript method that the button should trigger against (were I blanked out the approve-flag and called the build-in save-method).

    I don't know why I didn't think of this solution before.

    Thanks for all help, guys!

    regards,

    Marius (a happy man today)

    • Marked as answer by morris80 Saturday, March 25, 2017 11:50 AM
    Saturday, March 25, 2017 11:50 AM

All replies

  • Hi,

    Once a plugin encounters an exception, entire transaction is rolled back. You will have to make your plugin logic decide what you consider as a failure and then reset the flag, without your plugin failing with an exception. If you can't think of all reasons why your plugin will fail, this could be a difficult thing to achieve.

    I hope that was helpful.


    Sunday, January 15, 2017 3:59 PM
  • I understand the problem with the exception rolling back the entire transaction.
    But is there another solution for this?
    Maybe by using Javascript?

    Monday, January 16, 2017 8:22 AM
  • Anyone got any idea how to solve this issue?

    There muse be a way to reset a value after a plugin -exception?

    regards,

    Marius

    Tuesday, January 31, 2017 11:19 PM
  • Hi,

    If you set a value on entity A and the plugin is run on that update, the field shouldn't be set. What happens if you reload that form, is the value still set to 1?

    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

    Monday, February 6, 2017 1:36 PM
  • I have now tried to call a exernal web api from the exception-block.

    This web api tries to reset the flag on the same Lead (from its own CRM SDK). But this doesn't seems to work either..

    here is my plugin code (on exception):

    Here is were I call the web api:

    ..and here is the Web API Controller that tries to reset the flag:

    this doesnt seem to work either... anyone having a better solution?

    regards,

    Marius H. Enerud


    • Edited by morris80 Saturday, February 25, 2017 9:41 PM
    Saturday, February 25, 2017 9:40 PM
  • Anyone have an idea how to solve this issue?

    The problem is that I need to reset a attribute AFTER a plugin exception.

    regards,

    Marius

    Saturday, March 25, 2017 10:31 AM
  • Ahh!! I finally solved it:

    I used "Ribbon Workbench 2016", customized the native Save-button and made a new JavaScript method that the button should trigger against (were I blanked out the approve-flag and called the build-in save-method).

    I don't know why I didn't think of this solution before.

    Thanks for all help, guys!

    regards,

    Marius (a happy man today)

    • Marked as answer by morris80 Saturday, March 25, 2017 11:50 AM
    Saturday, March 25, 2017 11:50 AM