Home > Dynamics CRM 2011, Plugin > CRM 2011 Restrict Duplicate Personal View

CRM 2011 Restrict Duplicate Personal View

Recently we got a request from one of our user to restrict the personal view with same name. Having my previous blog in mind, thought that we can do something with User Query entity but when I am trying to register a plugin on User Query entity User Query is not listed.

I am stuck. Then I took the help of CRM Development Forum to solve this, thanks to Mahender and Gayan Perera.

As mentioned by Gayan, I updated the SdkMessageFilter & SdkMessageFilterasifPublished tables and set IsCustomProcessingStepAllowed to 1 on the userquery entity. Then I was able to see the userquery entity in the plugin registration list.

Used the below code to restrict the duplicates in the personal views

EntityCollection listrecords = new EntityCollection();
FilterExpression filterExp = new FilterExpression();
filterExp = new FilterExpression()
{
Conditions =
{
new ConditionExpression ("name", ConditionOperator.Equal, name)
}
};
QueryExpression query = new QueryExpression()
{
EntityName = "userquery",
ColumnSet = new ColumnSet(new string[] { "name" }),
Criteria = filterExp
};

listrecords = service.RetrieveMultiple(query);

if (listrecords.Entities.Count > 0)
throw new InvalidPluginExecutionException("Personel View with this name already exists.");

This has given us a way to solve this in an unsupported way. My manager agreed to go with unsupported way so I did. Hope this will help somebody…

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: