14 Most Used Realtime Business Use Cases for Plugin Scenario-Based Snippets in Dataverse & Dynamics 365
Plugins in Microsoft Dataverse and Dynamics 365 are one of the most powerful ways to implement realtime business logic. They allow developers to intercept operations such as Create, Update, Delete, Assign, Associate, and more.
In enterprise applications, plugins are commonly used to:
- Validate business rules
- Automate calculations
- Integrate external systems
- Prevent invalid operations
- Generate records automatically
- Maintain data consistency
- Trigger notifications
- Secure data processing
This blog covers 14 highly used realtime plugin scenarios with practical business examples and code snippets that developers frequently implement in real-world Dynamics 365 and Dataverse projects.
1. Prevent Duplicate Records
Business Scenario
A company wants to prevent users from creating duplicate customers with the same email address.
Use Case
- Avoid duplicate leads
- Prevent repeated contacts
- Maintain CRM data quality
Plugin Trigger
- Message: Create
- Table: Contact
- Stage: Pre-Validation
Plugin Snippet
public class PreventDuplicateContact : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity entity)
{
if (entity.Contains("emailaddress1"))
{
string email = entity["emailaddress1"].ToString();
QueryExpression query = new QueryExpression("contact")
{
ColumnSet = new ColumnSet("fullname")
};
query.Criteria.AddCondition("emailaddress1", ConditionOperator.Equal, email);
EntityCollection results = service.RetrieveMultiple(query);
if (results.Entities.Count > 0)
{
throw new InvalidPluginExecutionException("A contact with the same email already exists.");
}
}
}
}
}
2. Auto Generate Record Number
Business Scenario
An organization wants to generate a custom ticket number for support cases.
Example:
- CASE-1001
- CASE-1002
Plugin Trigger
- Message: Create
- Table: Case
- Stage: Pre-Operation
Plugin Snippet
public class GenerateCaseNumber : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity entity)
{
string generatedNumber = "CASE-" + DateTime.Now.Ticks.ToString().Substring(10);
entity["new_casenumber"] = generatedNumber;
}
}
}
3. Restrict Record Deletion
Business Scenario
A business wants to prevent users from deleting invoices after approval.
Plugin Trigger
- Message: Delete
- Table: Invoice
- Stage: Pre-Validation
Plugin Snippet
public class PreventInvoiceDeletion : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
EntityReference entityRef = (EntityReference)context.InputParameters["Target"];
Entity invoice = service.Retrieve(entityRef.LogicalName, entityRef.Id, new ColumnSet("statuscode"));
OptionSetValue status = invoice.GetAttributeValue<OptionSetValue>("statuscode");
if (status != null && status.Value == 100000001)
{
throw new InvalidPluginExecutionException("Approved invoices cannot be deleted.");
}
}
}
4. Auto Calculate Total Amount
Business Scenario
When order lines are added, the system should automatically calculate the total amount.
Plugin Trigger
- Message: Create/Update/Delete
- Table: Order Product
- Stage: Post-Operation
Plugin Snippet
Money price = entity.GetAttributeValue<Money>("priceperunit");
int quantity = entity.GetAttributeValue<int>("quantity");
decimal total = price.Value * quantity;
Entity updateOrder = new Entity("salesorder", orderId);
updateOrder["new_totalamount"] = new Money(total);
service.Update(updateOrder);
5. Send Notification on Status Change
Business Scenario
Whenever a lead becomes qualified, the sales manager should receive an email notification.
Plugin Trigger
- Message: Update
- Table: Lead
- Stage: Post-Operation
Plugin Snippet
if (entity.Contains("statuscode"))
{
OptionSetValue status = entity.GetAttributeValue<OptionSetValue>("statuscode");
if (status.Value == 3)
{
Entity email = new Entity("email");
email["subject"] = "Lead Qualified";
email["description"] = "A lead has been qualified.";
Guid emailId = service.Create(email);
}
}
6. Prevent Negative Inventory
Business Scenario
The warehouse team should not be able to reduce inventory below zero.
Plugin Trigger
- Message: Update
- Table: Product Inventory
- Stage: Pre-Operation
Plugin Snippet
int availableStock = existingEntity.GetAttributeValue<int>("new_availablequantity");
int requestedQty = entity.GetAttributeValue<int>("new_requestedquantity");
if (requestedQty > availableStock)
{
throw new InvalidPluginExecutionException("Insufficient inventory available.");
}
7. Auto Create Follow-Up Task
Business Scenario
When a new opportunity is created, automatically create a follow-up task for the sales executive.
Plugin Trigger
- Message: Create
- Table: Opportunity
- Stage: Post-Operation
Plugin Snippet
Entity task = new Entity("task");
task["subject"] = "Follow up with customer";
task["scheduledend"] = DateTime.Now.AddDays(2);
task["regardingobjectid"] = new EntityReference("opportunity", entity.Id);
service.Create(task);
8. Validate Business Hours
Business Scenario
Support tickets should only be created during office hours.
Plugin Trigger
- Message: Create
- Table: Case
- Stage: Pre-Validation
Plugin Snippet
TimeSpan currentTime = DateTime.Now.TimeOfDay;
TimeSpan start = new TimeSpan(9, 0, 0);
TimeSpan end = new TimeSpan(18, 0, 0);
if (currentTime < start || currentTime > end)
{
throw new InvalidPluginExecutionException("Cases can only be created during business hours.");
}
9. Synchronize Data Between Tables
Business Scenario
When account phone number changes, update related contacts automatically.
Plugin Trigger
- Message: Update
- Table: Account
- Stage: Post-Operation
Plugin Snippet
QueryExpression query = new QueryExpression("contact")
{
ColumnSet = new ColumnSet("telephone1")
};
query.Criteria.AddCondition("parentcustomerid", ConditionOperator.Equal, accountId);
EntityCollection contacts = service.RetrieveMultiple(query);
foreach (var contact in contacts.Entities)
{
contact["telephone1"] = updatedPhone;
service.Update(contact);
}
10. Restrict Unauthorized Field Updates
Business Scenario
Only managers should be allowed to update discount percentage.
Plugin Trigger
- Message: Update
- Table: Opportunity
- Stage: Pre-Validation
Plugin Snippet
if (entity.Contains("new_discountpercentage"))
{
bool isManager = CheckUserRole(service, context.UserId, "Sales Manager");
if (!isManager)
{
throw new InvalidPluginExecutionException("Only managers can update discount percentage.");
}
}
11. Auto Update SLA Status
Business Scenario
If a support case exceeds response time, update SLA status automatically.
Plugin Trigger
- Message: Update
- Table: Case
- Stage: Post-Operation
Plugin Snippet
DateTime createdOn = existingCase.GetAttributeValue<DateTime>("createdon");
if (DateTime.Now > createdOn.AddHours(4))
{
Entity updateCase = new Entity("incident", caseId);
updateCase["new_slastatus"] = "Breached";
service.Update(updateCase);
}
12. Block Inactive Customer Transactions
Business Scenario
Inactive customers should not be allowed to place new orders.
Plugin Trigger
- Message: Create
- Table: Order
- Stage: Pre-Validation
Plugin Snippet
Entity account = service.Retrieve("account", customerId, new ColumnSet("statecode"));
OptionSetValue state = account.GetAttributeValue<OptionSetValue>("statecode");
if (state.Value == 1)
{
throw new InvalidPluginExecutionException("Inactive customers cannot place orders.");
}
13. Auto Assign Records Based on Region
Business Scenario
Leads should automatically be assigned to regional sales representatives.
Plugin Trigger
- Message: Create
- Table: Lead
- Stage: Post-Operation
Plugin Snippet
string region = entity.GetAttributeValue<string>("address1_stateorprovince");
Guid ownerId = GetRegionalSalesRep(region);
AssignRequest assignRequest = new AssignRequest
{
Assignee = new EntityReference("systemuser", ownerId),
Target = new EntityReference("lead", entity.Id)
};
service.Execute(assignRequest);
14. Call External API from Plugin
Business Scenario
When a customer record is created, sync data with an external ERP system.
Plugin Trigger
- Message: Create
- Table: Account
- Stage: Post-Operation
Plugin Snippet
using (HttpClient client = new HttpClient())
{
var payload = new
{
Name = entity.GetAttributeValue<string>("name"),
Email = entity.GetAttributeValue<string>("emailaddress1")
};
string json = JsonConvert.SerializeObject(payload);
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync("https://api.contoso.com/customer", content).Result;
}
Plugin Best Practices
1. Use Correct Plugin Stage
- Pre-Validation → Validation logic
- Pre-Operation → Modify data before save
- Post-Operation → Actions after database commit
2. Avoid Infinite Loops
Always check plugin depth.
if (context.Depth > 1)
return;
3. Use Tracing Service
ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracing.Trace("Plugin execution started");
4. Minimize Service Calls
Retrieve only required columns.
new ColumnSet("name")
5. Prefer Secure Configuration
Avoid hardcoding:
- URLs
- API keys
- Credentials
Common Realtime Plugin Scenarios in Enterprises
Plugins are heavily used in industries such as:
| Industry | Common Use Cases |
|---|---|
| Banking | Fraud validation, KYC checks |
| Healthcare | Appointment validation, insurance checks |
| Retail | Inventory validation, order processing |
| Manufacturing | Production workflow automation |
| Education | Student approval workflow |
| Logistics | Shipment tracking automation |
| Insurance | Policy validation |
| Telecom | Service activation workflows |
Plugin Registration Recommendations
Recommended Execution Strategy
| Scenario | Stage | Mode |
|---|---|---|
| Validation | Pre-Validation | Synchronous |
| Auto Populate Fields | Pre-Operation | Synchronous |
| Notifications | Post-Operation | Asynchronous |
| External API Calls | Post-Operation | Asynchronous |
| Logging | Post-Operation | Asynchronous |
Final Thoughts
Plugins remain one of the most critical backend components in Microsoft Dataverse and Dynamics 365 implementations.
A well-designed plugin architecture helps organizations:
- Enforce business rules
- Improve automation
- Reduce manual work
- Ensure data consistency
- Integrate external systems efficiently
Mastering realtime plugin scenarios is essential for every Dynamics 365 and Power Platform developer.
If you are preparing for interviews, enterprise implementations, or solution architecture roles, these plugin use cases are among the most important scenarios to understand.








