Introduction
In Dynamics 365, plugins automate business processes, enforce rules, and ensure data integrity. Whether in Sales or Customer Service, plugins help streamline workflows by executing logic at the right time in the pipeline.
This post covers key plugin scenarios, detailing:
✅ Execution pipeline stage (Pre-Validation, Pre-Operation, Post-Operation)
✅ Synchronous or Asynchronous execution
✅ Pre-Image / Post-Image usage
✅ Rollback handling
Rollback Handling in Plugins
When Does a Plugin Rollback?
A plugin automatically rolls back if:
- An exception is thrown in a synchronous plugin.
- A transaction fails in a Pre-Validation or Pre-Operation stage.
How to Handle Rollbacks?
- Use Try-Catch Blocks: Prevent unwanted failures by catching errors and logging details.
- Throw an Exception When Needed: Stop invalid data changes (e.g., prevent closing an Opportunity without a Quote).
- Compensating Logic in Async Plugins: Since Post-Operation Async plugins do not participate in transactions, write logic to revert changes if required.
Sales: Automating Lead to Cash Processes
Create Scenarios
-
Auto-Assign a Sales Rep When a New Lead Is Created
- Pipeline Execution: Pre-Operation
- Execution Mode: Synchronous
- Image to Use: N/A
- Rollback Handling: If an error occurs, the Lead won’t be created.
-
Create a Task for Follow-Up When an Opportunity Is Created
- Pipeline Execution: Post-Operation
- Execution Mode: Asynchronous
- Image to Use: Post-Image
- Rollback Handling: If the Task creation fails, the Opportunity remains but without a follow-up task.
Update Scenarios
-
Update Opportunity Status Based on Quote Approval
- Pipeline Execution: Post-Operation
- Execution Mode: Synchronous
- Image to Use: Pre-Image & Post-Image
- Rollback Handling: If the update fails, the status change is rolled back.
-
Recalculate Estimated Revenue When Products Are Updated in an Opportunity
- Pipeline Execution: Post-Operation
- Execution Mode: Synchronous
- Image to Use: Pre-Image & Post-Image
- Rollback Handling: If an error occurs, the previous revenue calculation remains unchanged.
Delete Scenarios
-
Prevent Deleting a Lead If There Are Related Activities
- Pipeline Execution: Pre-Validation
- Execution Mode: Synchronous
- Image to Use: Pre-Image
- Rollback Handling: If an exception is thrown, the Lead deletion is fully rolled back.
-
Automatically Reassign Open Opportunities If a Sales Rep Leaves
- Pipeline Execution: Post-Operation
- Execution Mode: Asynchronous
- Image to Use: Pre-Image
- Rollback Handling: As an async plugin, failure won’t rollback the user deactivation. Consider logging failures and retrying.
Customer Service: Enhancing Case Management
Create Scenarios
-
Auto-Assign Case to a Queue When Created
- Pipeline Execution: Pre-Operation
- Execution Mode: Synchronous
- Image to Use: N/A
- Rollback Handling: If an error occurs, the Case won’t be created.
-
Create a Customer Notification When a Case Is Created
- Pipeline Execution: Post-Operation
- Execution Mode: Asynchronous
- Image to Use: Post-Image
- Rollback Handling: If the email fails, the Case is still created, but no notification is sent.
Update Scenarios
-
Escalate Cases That Are Open for More Than 48 Hours
- Pipeline Execution: Post-Operation
- Execution Mode: Asynchronous
- Image to Use: Pre-Image & Post-Image
- Rollback Handling: Since this is async, failure won’t rollback the Case update but should be logged.
-
Prevent Closing a Case If There Are Open Activities
- Pipeline Execution: Pre-Validation
- Execution Mode: Synchronous
- Image to Use: Pre-Image
- Rollback Handling: If an exception is thrown, the Case remains open.
Delete Scenarios
-
Restrict Deleting Cases That Have a Resolution Logged
- Pipeline Execution: Pre-Validation
- Execution Mode: Synchronous
- Image to Use: Pre-Image
- Rollback Handling: If an exception is thrown, the Case deletion is fully rolled back.
-
Automatically Close All Open Tasks When a Case Is Deleted
- Pipeline Execution: Post-Operation
- Execution Mode: Asynchronous
- Image to Use: Pre-Image
- Rollback Handling: If task closure fails, the Case is still deleted, leaving orphaned records. Consider using transactions or compensating logic.
Each plugin scenario ensures smooth business operations, executing at the right stage in the pipeline, with appropriate synchronous or asynchronous execution, and leveraging rollback mechanisms when necessary.
By implementing these Sales and Customer Service plugins, organizations can enhance automation, enforce business rules, and improve data consistency in Dynamics 365.
Want to see detailed C# implementations of these plugins? Comment or let me know on my LinkedIn profile : Pavan Kumar Vuyyuru





Comments
Post a Comment