Some time user required to hide some system defined views from any entity in CRM 4.0,
to do this we need to create a plug-in.
For Example: hare you can hide "All My Leads" and "My Closed Leads" view's from my lead entity.
Use the following code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Metadata;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
namespace HideViewsPlugin
{
public class HideViews : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
// Query the SavedQueryBase table to retrieve the Query Id for an attribute savedqueryid
Guid[] Views = new Guid[] {
new Guid("5F001E93-3C6D-DE11-991A-0019B9F5ED8F"), //All My Leads
new Guid("36AA1011-4F6C-DE11-991A-0019B9F5ED8F"), //My Closed Leads
};
if (context.InputParameters != null && Views.Length > 0)
{
if (context.InputParameters.Properties.Contains(ParameterName.Query))
{
QueryExpression qe = (QueryExpression)context.InputParameters.Properties[ParameterName.Query];
//only apply this action if the query is for 'views' or saved queries
if (qe.EntityName == "savedquery")
{
if (qe.Criteria != null)
{
if (qe.Criteria.Conditions != null)
{
//Append more condition logic to the default query that's used by CRM. In this case, I filtered on the savedqueryid to exclude the views from the Ids identified above.
//This conditional expression hide only two defined Views
ConditionExpression queryCondition = new ConditionExpression("savedqueryid", ConditionOperator.NotIn, Views);
OR
//If you required to hide all the Views starting from a specific string then use the below defined ConditionExpression
/*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);
context.InputParameters.Properties[ParameterName.Query] = qe;
}
}
}
}
}
}
}
}
Now register this plug-in and register one more Step for this plug-in,Parametters those required for step are given below:
Meggage: RetrieveMultiple
Primary Entity: savequery
Eventing Pipline: Pre Stage
Execution Mode: Synchronous
Step Deployment: Server
Triggering Pipeline: Parent Pipeline
I am running this Blog to help other guys, who are looking some bits and pieces in terms of MS technology....
Subscribe to:
Post Comments (Atom)
Split the String values with a special character in MS Flow to convert this into Array
Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...
-
Use the following line of code to Reopen the closed task in CRM 2011 // Re-open the Task to update it SetStateRequest ssr = new SetStat...
-
Use the following line of code to create complete workflow activity with two output parameters. 1) Open Visual Studio 2010 ID. 2) Open ...
-
Sometimes you experienced when you have subgrid in your CRM Form, but when you click the ‘expand’ button to expand the view then it will re...
No comments:
Post a Comment