Archive

Posts Tagged ‘sdkmessagefilter’

CRM 2011 Restrict Duplicate Personal View

November 22, 2011 Leave a comment

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