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)

Plugin: Delete own system job entry while executing

(0) ShareShare
ReportReport
Posted on by

I have a few plugins that is run whenever a field is updated, but sometimes the field is updated to a value the plugin doesn't need to handle, and an if-statement prevents the rest of the plugin code from being run. But in the system job log, one can't see if the plugin execution was preventet - it just says successful. I'd like to be able to see in the log when the plugin was actually run, so I can't check Delete AsyncOperation when successful.

I could throw an InvalidPluginExecutionException with OperationStatus.Cancelled, but I feel like this just clutters the system job log.

Is there a way for the plugin to delete its own system log entry, and would it be safe to do so? Does CRM expect the system log to be there after it is run?

Does checking Delete AsyncOperation also delete thrown InvalidPluginExcecutionException's with OperationStatus.Successful? If not, I could just throw that whenever the plugin successfully ran all its code, and 'return' whenever the code didn't need to run.

Don't know if this can be solved with workflows, but I'd rather not use them.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    prt33k Profile Picture
    6,907 on at

    Hi Jan,

    If there are fields updates which are not to be handled by plugin then why not to exclude them from filtering attributes while registering the plugin?

    Filtering Attributes are list of entity attributes that cause the plug-in to execute when it is changed and can be configured in plugin registration tool.

    This will make the plugin trigger only when the desired fields are updated.

    Thanks,

    PS

  • Community Member Profile Picture
    on at

    Hi PS

    When the statecode is updated to Submitted, the order is sent to Nav. Later, when the invoice is paid and the order have been processed, the statecode goes to Fulfilled. I only need to act on Submitted. It's the same field so I can't filter the update messages any further.

  • prt33k Profile Picture
    6,907 on at

    Hi Jan,

    I dont prefer plugin/workflow deleting system job. Plugin/Workflow should work at the business layer only.

    Usually there can be scheduled job which delete the log entries after a month or so.

    But if that is also not a option then you can create a custom field - statecodefield - which will get updated only when statecode is Submitted. You can then put this field in filtering attribute of your plugin.

    Thanks,

    PS

  • Community Member Profile Picture
    on at

    The job entry needs to be deleted immediately, so it doesn't say Send submitted order to Nav twice, when it's only happened once. It was just an example, so creating new fields for every plugin not needing to run for some field values would clutter the entities by showing up in the autogenerated code, in the database as a column and in various other places.

  • Verified answer
    Community Member Profile Picture
    on at

    Working solution:

    * Mark step with "Delete AsyncOperation if StatusCode = Successful"

    * Sample code:

    public void Execute(IServiceProvider serviceProvider)
    {
        if (my_object.value != value_valid_for_this_plugin)
            return; // System job is deleted
    
    // Job will show up in system job log throw new InvalidPluginExecutionException(OperationStatus.Succeeded); }


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