Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin: Delete own system job entry while executing

Posted on by Microsoft Employee

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin: Delete own system job entry while executing

    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); }


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin: Delete own system job entry while executing

    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.

  • prt33k Profile Picture
    prt33k 6,907 on at
    RE: Plugin: Delete own system job entry while executing

    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
    Community Member Microsoft Employee on at
    RE: Plugin: Delete own system job entry while executing

    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.

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: Plugin: Delete own system job entry while executing

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans