This is a post following CRM 2011: Offline Plugin – Assembly Security Registry. In this post we are going to discuss about modifying plugin code to support offline execution.
The important thing to remember here is that the plugin that is running both online and offline may execute twice. Please note the use of the word may and not will.
Things to consider:
1. Obviously, plugin may run twice.
2. Does a plugin need to run offline or if it’s just a nice-to-have feature? Eg. business rules validation
3. Data might not be available offline which may be required by the plugin – Offline Filters. Eg. unique number generation
4. CRM 4.0: manually assign guid to new record.
MSCRM context has two properties to determine the status of plugin execution.
IsExecutingOffline property to determine whether the plugin is executing in offline mode.
IsOfflinePlayback property to determine whether the plugin is executing because of synchronization process (executing the second time)
For CRM 4.0, these properties are named differently.
CallerOrigin just use
if (context.CallerOrigin is OfflineOrigin)
For more information for MSCRM 4.0, read the MSDN articles below:
Online vs. Offline Plug-ins
Creating a Plug-in for Microsoft Dynamics CRM for Outlook that Works Offline
Cheers – Sy