CRM 2015: How to register a plugin for a Global Custom Action using CRM Toolkit

Scenario: I have a custom action that is registered against global (None), but I want to create a plugin that will execute my logic when the action is invoked. These are the steps I took to register the plugin using the CRM toolkit.

  • Create a plugin against any entity in the system, I prefer to use the system user entity. Select the normal plugin setting i.e. Message, Pipeline Stage etc.
  1. 1Then modify the plugin created in step 1, first update the message to the name of your custom action, secondly update the name of the entity to an empty string




  • Open the RegisterFile of the CrmPackage and update the plugin created in step 1. Firstly update the MessageName to your custom action name, secondly remove the PrimaryEntityName=”systemuser” tag completely and save the file.





  • Rebuild your project, deploy and test.

CRM 2015 Plugins – Avoiding Infinite Loops

This has been a pain for quite some time and have been using (localContext.PluginExecutionContext.Depth > 1) to avoid the infinite plugin loop. BUT this also creates another problem when the plugin suppose to execute either during data import or when using a workflow to create/update.

Problem SOLVED by using localContext.SharedVariables in the plugin. First you need a function to check if the SharedVariables exist before executing your plugin logic, if it does not exist then add it. The trick is to check the SharedVariables in the parent context of the context. See below code:

protected void ExecutePostCaseUpdate(LocalPluginContext localContext)
if (localContext == null)
throw new ArgumentNullException(“localContext”);

if (!CheckRecursionIndicator(localContext.PluginExecutionContext, “ExecutePostCaseUpdateIndicator”)) return;
var updateCase = ((Entity)localContext.PluginExecutionContext.InputParameters[“Target”]).ToEntity();

// TODO: Implement your custom Plug-in business logic.
updateCase.Title = “Plugin Shared Viarable Test”;

/// Check plugin loop recursion

private bool CheckRecursionIndicator(IPluginExecutionContext context, string recursionIndicator)
if (!context.SharedVariables.Contains(recursionIndicator))
while (context.ParentContext != null)
if (context.ParentContext.SharedVariables.Contains(recursionIndicator))
return false;
context = context.ParentContext;

context.SharedVariables.Add(recursionIndicator, (Object)true);
return true;

Microsoft Dynamics CRM 2015 :Release Preview Guide

Click Here to view the release guide.

Microsoft Dynamics CRM 2013 Spring ’14 Release Videos

Microsoft has put together YouTube videos for the Spring ’14 Release. Click here for more information.

Rollup 3 for Microsoft Dynamics CRM 2013

Microsoft Dynamics CRM 2013 rollup 3 is now available here for download.


Blogs about all tips and tricks on Dynamics CRM

Mark Margolis's Blog

It's about Software, CRM, Product Development and sometimes Food.


Gareth Tucker on Microsoft Dynamics CRM

Donna Edwards

Microsoft Dynamics CRM News

The latest news on and the WordPress community.