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

2 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?

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