Who triggered my plugin?

Do you ever want to know who triggered the execution of a plugin? This knowledge is handy, if you have to do some operation if the user entered data, but not if an external application made an update with the SDK.

The IPluginExecutionContext contains the property CallerOrigin which will tell us more about the origin which triggered the plugin execution.

The CallerOrigin is populated with one of these four types

  • Application – The user has triggered the event (by creating or editing a record).
  • AsyncService – The async service triggered the event (by workflow execution).
  • WebServiceApi – An application which makes use of the crm web service triggered the event.
  • OfflineOrigin – The event was triggered by replaying offline actions while going online.

This sample shows how to make use of this property (the sample is part of the sdk article Online vs. Offline Plug-ins)

using System;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
public class OnlinePlugin : IPlugin
   public void Execute(IPluginExecutionContext context)
      // Check to see if this is a playback context.
      CallerOrigin callerOrigin = context.CallerOrigin;
      if (callerOrigin is OfflineOrigin)
         // This plug-in was fired from the playback queue after the user
         // selected to go online within Microsoft Dynamics CRM for Outlook.
         // Do something here.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.