Code-Based Customization in Dynamics 365 CRM
1. When to Use Code Customization
Use it when:
-
Business rules can’t be expressed via Business Rules, Flows, or OOB features.
-
You need real-time server-side logic, complex data validation, or integration with external systems.
-
You want to build custom UI components or automate client-side behavior.
2. Types of Code-Based Customization
a. Plugins (Server-side C# logic)
-
What: Event handlers that execute during record events (Create, Update, Delete, Assign, etc.)
-
Where: Registered via Plugin Registration Tool or inside a solution.
-
Use cases:
-
Validate field dependencies
-
Auto-generate values
-
Integrate with external APIs
-
-
Execution pipelines:
-
Pre-validation, Pre-operation, Post-operation
-
-
Run in: Synchronous or Asynchronous modes
b. Custom Workflows (Deprecated but still used)
-
Custom logic triggered via workflow processes.
-
Replaced mostly by Power Automate or plugins.
c. JavaScript (Client-side logic)
-
What: Executes in the browser on forms and views.
-
Use cases:
-
Field validation and conditional visibility
-
Auto-populate values
-
Form-level business logic
-
-
Tools: Web Resources + Form Editor
d. Custom Connectors / APIs
-
Use case: Integrate CRM with external systems via REST APIs.
-
Options:
-
Webhooks
-
Azure Functions
-
Logic Apps or Middleware
-
e. PCF (PowerApps Component Framework)
-
What: Build custom UI components for forms or dashboards.
-
Tech: TypeScript + React (typically)
-
Use case:
-
Data grids with advanced formatting
-
Map components, sliders, charts
-
-
Works in Model-Driven Apps and Canvas Apps.
3. Do's and Don'ts for Code Customization
| DOs | DON'Ts |
|---|---|
| Use plugin isolation and sandbox model | Don’t use unmanaged code or reflection hacks |
| Keep plugin logic modular and reusable | Avoid large, complex plugins with 100s of lines |
| Use Dependency Injection (new SDK supports it) | Don’t hardcode connections or settings |
| Use JavaScript only when UX needs it | Don’t replicate server logic in JS |
| Write unit-testable business logic in shared libraries | Avoid direct calls to external APIs inside plugins |
| Log exceptions with TracingService | Don’t ignore error handling or retry logic |
| Follow naming conventions and version control | Don’t deploy code changes directly in production |
4. Tools Commonly Used
-
Plugin Registration Tool (PRT)
-
Visual Studio (for C# plugins, workflows)
-
TypeScript + VS Code (for PCF)
-
XrmToolBox for metadata work
-
Fiddler/Postman for API testing
5. Example Use Case
Scenario: On Opportunity close, send customer data to an external billing system.
Solution:
-
Register a Post-Operation Plugin on Opportunity Close.
-
Call external API using
HttpClient. -
Log response and update Opportunity with billing status.