locked
How to hide some system views? RRS feed

  • Question

  • I'd like to hide some system views, for example:

    • Accounts: No Campaign Activities in the Last 3 Months -- we won't be using campaign activities
    • Accounts: No Orders in the Last 6 Months -- we won't be using orders
    • Accounts: Responded to Campaigns in the Last 6 Months -- we won't be using campaign responses

    However, I've tried hiding them by exporting the Account entity XML, commenting out or even deleting these views, and importing the entity back in to CRM. Is the only way to hide system views to use a plugin like Darren Liu's or David Jennaway's? I know that some of the CRM system views can't be deleted, but I thought they would be easier to hide.

    Neil

    Tuesday, April 6, 2010 1:45 PM
    Moderator

Answers

  • Well, you must consider this as a default behavior of the product. It is not possible to delete system view from an entity. 

    And if you delete it form the XML customization, when importing, it doesn't delete it...

    So it seems "normal"...


    My blog : http://mscrmtools.blogspot.com
    You will find:
    Bulk Delete LauncherView Layout replicator
    ISV.Config Manager Form Javascript Manager
    Assembly RecoveryAnd others (use tool tag on my blog)
    Tuesday, April 6, 2010 1:58 PM
    Moderator

All replies

  • Hello Neil,

    You can see below an example How to hide system view  with plugins : http://msdynamicscrm-e.blogspot.com/2008/02/hiding-view-in-crm-40-using-plug-in.html

    Lassaad,

    Tuesday, April 6, 2010 1:50 PM
  • I don´t think there´s an easier way instead of using plugins for this.
    Gruß Carsten Groth http://carstengroth.spaces.live.com
    • Proposed as answer by ckeller Tuesday, April 6, 2010 2:55 PM
    Tuesday, April 6, 2010 1:56 PM
  • Thanks Lassaad, your link to Darren's plugin was the same one as in my original post. I was really just wondering why: (a) some system views can't be hidden without resorting to a plugin, and (b) how come deleting the XML definition for a view doesn't remove the view from the entity definition?

    Neil

    Tuesday, April 6, 2010 1:56 PM
    Moderator
  • Well, you must consider this as a default behavior of the product. It is not possible to delete system view from an entity. 

    And if you delete it form the XML customization, when importing, it doesn't delete it...

    So it seems "normal"...


    My blog : http://mscrmtools.blogspot.com
    You will find:
    Bulk Delete LauncherView Layout replicator
    ISV.Config Manager Form Javascript Manager
    Assembly RecoveryAnd others (use tool tag on my blog)
    Tuesday, April 6, 2010 1:58 PM
    Moderator
  • this thing has been facilitated in MS CRM 2011, we can achieve it by just deactivating the Views (can not just deactivate the default view).

    So if you wan to do deactivate a view which is already default, then make anothe rview as default and deactivate the old default view.

    Regards,

    Sudhanshu


    yes.sudhanshu

    http://bproud2banindian.blogspot.com
    http://ms-crm-2011-beta.blogspot.com

    Monday, September 17, 2012 3:24 AM
  • Hi Neil,

    I followed the above link ,what Lassaad.Cabani  has shared already...

    my requirement was need to hide views based on the security role:

    public class HideViewsBySecurityRole:IPlugin
        {
    
            Dictionary<int, StringCollection> hideViews;
            Dictionary<int,StringCollection> securityRoles;
    
            public HideViewsBySecurityRole(string unsecureConfig, string secureConfig)
            {
                 StringCollection sc = new StringCollection();
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(secureConfig);
                    hideViews = new Dictionary<int, StringCollection>();
                    foreach (XmlElement entityNode in doc.SelectNodes("/entities/entity"))
                    {
                        sc = new StringCollection();
                        foreach (XmlNode viewNode in entityNode.ChildNodes)
                        {
                            sc.Add(viewNode.InnerText);
                        }
                        string sOTC = entityNode.GetAttribute("otc");
                        if (!String.IsNullOrEmpty(sOTC))
                        {
                            int otc = 0;
                            int.TryParse(sOTC, out otc);
                            if (otc != 0)
                                hideViews.Add(otc, sc);
                        }
                    }
    
                    securityRoles = new Dictionary<int, StringCollection>();
                     foreach (XmlElement entityNode in doc.SelectNodes("/entities/sroles"))
                    {
                         sc = new StringCollection();
                        foreach (XmlNode roleNode in entityNode.ChildNodes)
                        {
                            sc.Add(roleNode.InnerText);
                        }
                        
                                securityRoles.Add(1, sc);
                        
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        System.Diagnostics.EventLog.WriteEntry("MSCRMWebService", "Excitation.PluginHideSystemViews.CheckView Constructor: " + ex.Message);
                        hideViews = new Dictionary<int, StringCollection>();
                    }
                    catch { }
                }
                sc = null;
            }
            public bool CheckLoggedInUserRole(IOrganizationService service,Guid userId)
            {
    
                try
                {
                   
                  ConditionExpression conExp = new ConditionExpression();
                    conExp.AttributeName = "systemuserid";
                    conExp.Operator = ConditionOperator.Equal;
                    conExp.Values.Add(userId);
    
                    FilterExpression filter = new FilterExpression();
                    filter.FilterOperator = LogicalOperator.And;
                    filter.AddCondition(conExp);
    
                    QueryExpression query = new QueryExpression();
                    query.EntityName = "role";
                    query.ColumnSet = new ColumnSet("name");
                    //query.Criteria = filter;
    
                    query.LinkEntities.Add(new LinkEntity("role", "systemuserroles", "roleid", "roleid", JoinOperator.Inner));
                    query.LinkEntities[0].EntityAlias = "role";
    
                    query.LinkEntities[0].LinkEntities.Add(new LinkEntity("systemuser", "systemuserroles", "systemuserid", "systemuserid", JoinOperator.Inner));
                    query.LinkEntities[0].LinkEntities[0].EntityAlias = "systemuserrole";
    
                    query.LinkEntities[0].LinkEntities[0].LinkCriteria = filter;
    
                    RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
                    retrieve.Query = query;
                    
                    RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
    
                    EntityCollection entityCollection = (EntityCollection)retrieved.EntityCollection;
    
                    StringCollection scHide = securityRoles[1];
                    foreach (Entity role in entityCollection.Entities)
                    {
                        if (role.Contains("name") && scHide.Contains((string)role["name"]))   // Hide this view - i.e. remove it from the collection of returned views
                            return true;
                    }
                   
                }
                catch (Exception Ex)
                {
                    LogEvent objEventLog = new LogEvent();
                    objEventLog.WriteEventLogEntry("HideViews::->Exception::" + Ex.Message + " -->Trace::" + Ex.StackTrace.ToString());
                    throw new InvalidPluginExecutionException(
                    "An error occurred in the plug-in.", Ex);
                }
                return false;
            }
            public void Execute(IServiceProvider serviceProvider)
            {
                string applicationRole = string.Empty;
                Guid appRoleId = Guid.Empty;
    
                LogEvent objEventLog = null;
    
                try
                {
    
                    IPluginExecutionContext context = (IPluginExecutionContext)
                    serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                    IOrganizationServiceFactory serviceFactory =
                                        (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                    if (CheckLoggedInUserRole(service,context.UserId))
                    {
                        objEventLog = new LogEvent();
                        if ((context.MessageName == "RetrieveMultiple" && context.PrimaryEntityName == "savedquery" && context.InputParameters.Contains("Query") && context.OutputParameters.Contains("BusinessEntityCollection")))
                        {
    
                            QueryExpression qe = context.InputParameters["Query"] as QueryExpression;
                            if (qe == null)         // Check it's a QueryExpression
                                return;
    
                            ConditionExpression cond = GetCondition(qe.Criteria, "returnedtypecode");
                            if (!(cond != null && cond.Operator == ConditionOperator.Equal && cond.Values.Count == 1 && cond.Values[0] is int))       // Check there is an equiality condition on returnedtypecode for an integer value
                                return;
    
                            int otc = (int)cond.Values[0];
    
                            if (!hideViews.ContainsKey(otc))       // Check that we want to exclude views for this entity
                                return;
    
                            EntityCollection becViews = (EntityCollection)context.OutputParameters["BusinessEntityCollection"];
    
                            if (!(becViews != null && becViews.EntityName == "savedquery"))  // Check there are some views, and they are the right type
                                return;
    
                            StringCollection scHide = hideViews[otc];
                            for (int i = becViews.Entities.Count - 1; i >= 0; i--)      // Iterate backwards, as items may be removed
                            {
                                Entity de = (Entity)becViews.Entities[i]; // BusinessEntityCollection is of type DynamicEntity
    
                                if (de.Contains("name") && scHide.Contains((string)de["name"]))   // Hide this view - i.e. remove it from the collection of returned views
                                    becViews.Entities.RemoveAt(i);
                            }
                        }
                    }
    
    
                }
                catch (FaultException<OrganizationServiceFault> ex)
                {
                    objEventLog.WriteEventLogEntry("HideViews::->Exception::" + ex.Message + " -->Trace::" + ex.StackTrace.ToString());
                    throw new InvalidPluginExecutionException(
                    "An error occurred in the plug-in.", ex);
    
                }
                objEventLog = null;
            }
            private ConditionExpression GetCondition(FilterExpression Filter, string Attribute)
            {
                ConditionExpression ret = null;
                if (Filter != null && Filter.Conditions != null)
                    for (int i = 0; i < Filter.Conditions.Count; i++)
                    {
                        ConditionExpression cond = (ConditionExpression)Filter.Conditions[i];
                        if (cond.AttributeName == Attribute)
                        {
                            ret = cond;
                            break;
                        }
                    }
                return ret;
            }
        }


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful. -------------------------------------------------------------------------------- Jhansi

    Monday, September 17, 2012 7:11 AM