C# · Dynamics CRM 2011 · Plugin

CRM 2011: Programmatically Filter/Hide Entity Views using Plugin

I had to filter pre-defined views used only for subgrids in forms so they don’t appear in views selection on entity grid.

To easily mark those views that should not appear, I have prefixed their names with the word ‘Hidden’.

The next step is to create a Plugin that filters views with the word ‘Hidden’ on retrieve multiple event of savedquery entity (synchronous pre-stage of course).

public void Execute(IServiceProvider serviceProvider)
{
	// Obtain the execution context from the service provider.
	IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

	// The InputParameters collection contains all the data passed in the message request.
	if (context.InputParameters.Contains("Query") && context.InputParameters["Query"] is QueryExpression)
	{
		QueryExpression qe = (QueryExpression)context.InputParameters["Query"];
		if (qe.EntityName == "savedquery")
		{
			if (qe.Criteria != null)
			{
				if (qe.Criteria.Conditions != null)
				{
					/*The query is edited to look at views not starting with "Hidden" at the begining of the View Name*/
					ConditionExpression queryCondition = new ConditionExpression("name", ConditionOperator.NotLike, "Hidden%");
					qe.Criteria.Conditions.Add(queryCondition);
				}
			}
		}
	}
}

Cheers – Sy

Advertisements

4 thoughts on “CRM 2011: Programmatically Filter/Hide Entity Views using Plugin

  1. Thank you for the post. Can you use a plugin to hide a tab or a section on a form inplace of Javascript?

  2. Hi there, i am implementing the same code as yours in Microsoft Dynamics CRM 2016 on prem but no change occurs in the views. could you please help me out? thanks

    1. Hi Amna,

      The plugin should still work in CRM 2016 as the mechanism is still the same. Can you tell me what you have done?

      Cheers,
      Sy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s