web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to create a log when throw InvalidPluginExecutionException in a sync plugin

(0) ShareShare
ReportReport
Posted on by 91

Hello,

I have an sync plugin for sending date to another system, and I create an new entity   new_log to log the data sent or exception.

the main logical is that

try

{
logCenter.Init(crmservice)//to init logcenter by passing crm org service to it 

SendData();
logCenter.Trace("OK","blablabal");

}catch(ex)

{ 
logCenter.Trace("Failed","blablabal");
throw new InvalidPluginExecutionException();

}


the problem is that as the plugin is registered on sync mode, when there is an exception,  the log can not be created by logCenter, I think it was created but then was rollback by the plugin? Do you have any idea if I want to write the log by create a new crm record?

will it be OK if I make a new ACTION dedicated for the log?

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PranavShroti Profile Picture
    4,510 on at

    you can always write Finally {} block if you want to log.

    If found useful, please mark the answer as verified

    Regards,

    Pranav

  • Suggested answer
    MS CRM DYNAMICS Profile Picture
    592 on at

    Please check below link.

    https://www.inogic.com/blog/2017/03/plugin-pre-validation-operation-to-show-an-error-message-as-well-as-log-the-error/

    If found useful, please mark answer as verified.

  • gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Please find below reference how to enable plugin trace in dynamics CRM.

    www.powerobjects.com/.../debugging-your-plug-ins-with-the-plug-in-trace-log

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Yes you are correct. If you throw the exception from plugin, it will rollback the database transaction. However you can register your plugin on PreValidation stage which is outside of the database transaction so any operation performed here will persists.

    You can read more about stages here: docs.microsoft.com/.../gg327941(v=crm.8)

    Hope this helps.

  • Daniel Wikell Profile Picture
    2,360 on at

    And since no one answered your last question: Yes making a new Action for log registration and calling that from your plugin would work since the action is not executed in your pipeline and thus not part of the rollback.

  • Song Profile Picture
    91 on at

    Hi Pranav,

    We have already tried the Finally block but it will be rollbacked...Thanks

  • Song Profile Picture
    91 on at

    Hi, we have to register the plugin in post-operation, I forgot to point it. so change it to pre-validation state is not OK for me.

    Thanks

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Then you can try with custom action.

  • Song Profile Picture
    91 on at

    Hi, I have tried it yesterday and it was rollbacked, I make a custom action and call it just before throwing the exception.  it was rollbacked for post and pre-operation but OK for pre-validation...

    thanks

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Then I think you can't do this in plugin. You will have to move your code from plugin to custom workflow activity with the some string output parameter say "Returned Message" and then use that within the workflow to identify if the execution is sucessfull or not by returning the exception in the Returned message parameter. Within the workflow, check if returned paramter has any value, if yes, then cancel the workflow execution and display the error message returned by the custom workflow.  

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans