locked
Throw exception and also logs the error in the custom entity in dynamics crm 2013 online plugins RRS feed

  • Question

  • Hi,

    Is there a way in the dynamics crm online plugin, if there is any error occurs then we should be able to show it to the user and also logs it in any custom entity. Both should be at the same time.

    Kindly let me know asap.

    Thanks and Regards

    Sandeep

    Friday, May 23, 2014 10:58 AM

All replies

  • Hi SAndeep,

    Yes, there is a way, but need some customization.

    Yes, you can. In your plugin, you have try catch,right?

    To show the error message in plugin to be shown by user in the screen, you can have try catch, and in the catch {}, you can put the coding :

    catch (Exception ex)

                   {

                       throw new InvalidPluginExecutionException(ex.Message);

                   }

    If make user enable to see the error message and as well to download the error log.

    You can add custom error log in the error.log file by adding tracing service, it is stated in the CRM SDK.

    //create tracing service

               ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    tracingService.Trace(yourMessage);

    Please refer to this link as well.

    inogic.com/.../use-tracing-in-crm-2011-plugins

    But, those error logs are not permanent, meaning that only temporary shown to the user in the UI screen and then user download the error log.

    Then, to get the permanent error that can be seen by anyone not immediately after the error occurs, you can save to the custom entity as log entity.

    Then in the catch before you throw new invalidplugin, then can you have an error handling, by creating a custom entity, maybe the fields has the following field as standard : Entity Name, Message Name (in which message your plugin has error), Timestamp, and the Error Message, and also the calling user as the standard fields, you can have any other field you want. You also can add, for example : the Id of the record that trigger an error (for existing record).

    That all what we did before, creating a custom entity to store the log.

    Then, you can refer back your custom log entity to get the errors.

    For your additional information, check this link, I find out for you.

    www.avanadeblog.com/.../error-logging-plug-in-exceptions-in-crm-online.html

    Be remember that for the asynchronous plugin, because it runs on background, so user cannot see the error message, but can see through the system job message.

    Thanks!

    Monday, May 26, 2014 3:39 PM