locked
CRM 2011: Plugin - What is the best way to return status/error messages from a plugin back to the user? RRS feed

  • Question

  • I'm using InvalidPluginExecutionException() to return an error from the plugin back to the user. But the format displayed to the user is a bit odd. What is the best way to deal with returning a message I want to format for a user-level message?

    Here's what I am doing...  I have a post-entity-update plugin to evaluates the current entity for a set of validations such as...

    1. If checkbox-X is checked, at least one associated record needs to exist for entity-X.
    2. If any related records exists for entity-X, then at least one of the related entity-X records must have a phone number.

    I have about 6 of these sorts of checks and the list is continuing to grow.  So I decided the best place to deal with this is in a plugin.  But I want the message  returned back to the user to be formatted a little nicer than the default plugin exception.  Is that possible?

    I have considered storing the messages in a hidden field, creating a new error entity, etc.  But it seems that such a common need would have already been well addressed in CRM.

    Any suggestions?  Any ideas or recommendations are much appreciated.

    Best regards,


    Jon Gregory Rothlander



    Wednesday, April 8, 2015 2:53 PM

Answers

  • I was able to accomplish this by creating a message class in my plugin, then serializing it to JSON and placing it in a hidden field on the form.  When the plugin finishes and returns control back to the CRM form, I am able to evaluate the value from the hidden message field on the form_load function in JavaScript.  In that process I am able to parse the JSON messages and throw alerts to the user. 

    I need this because I need to send back messages to the user that are simply warnings. I am doing much more, but this is the core issue I could not accomplish without this, that is to send non-fatal messages from the plugin back to the user.  So I want the plugin to save but also to return a message to the user that I am display through an alert.

     

    Jon Gregory Rothlander

    • Marked as answer by jonrothlander Monday, April 20, 2015 7:04 PM
    Monday, April 20, 2015 7:04 PM

All replies

  • Hello,

    You can't do much with formatting in the plugin exception message, but as a workaround you can utilize itracingservice and log all your formatted exception there, once done in the last you can simply throw a message saying "Error occurred please download log file for more details", so user should get formatting message in log file.

    Hope it will help you.

    Thanks.


    Microsoft Dynamics CRM Training|Our Blog | Follow US | Our 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.

    Wednesday, April 8, 2015 3:08 PM
    Moderator
  • I was able to accomplish this by creating a message class in my plugin, then serializing it to JSON and placing it in a hidden field on the form.  When the plugin finishes and returns control back to the CRM form, I am able to evaluate the value from the hidden message field on the form_load function in JavaScript.  In that process I am able to parse the JSON messages and throw alerts to the user. 

    I need this because I need to send back messages to the user that are simply warnings. I am doing much more, but this is the core issue I could not accomplish without this, that is to send non-fatal messages from the plugin back to the user.  So I want the plugin to save but also to return a message to the user that I am display through an alert.

     

    Jon Gregory Rothlander

    • Marked as answer by jonrothlander Monday, April 20, 2015 7:04 PM
    Monday, April 20, 2015 7:04 PM