Sunday, November 22, 2015

Hide view in CRM

If you have any doubt in the post please post comments. I will try to solve your problem.

Some times we would need hide some view based on the roles. The below i have simply hide the view by the name starts with "my".

Plugin Code:
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)
                               {
//Custom logic can also apply
                                   /*The query is edited to look at views not starting with "my" at the begining of the View Name*/
                                   ConditionExpression queryCondition = new ConditionExpression("name", ConditionOperator.NotLike, "my%");
                                   qe.Criteria.Conditions.Add(queryCondition);
                               }
                           }
                       }
                   }
Plugin Configuration:
Meggage:  RetrieveMultiple
Primary Entity: savequery
Eventing Pipline: Pre-validation


Hide view based on Roles:
  • In custom logic code mention in the plugin area.
  • Get the role name based on the current logged in user
  • Form the list of roles that user have to display the view
  • Check if the user has able to display the view or not based on list
  • If not then filter with view name not to display 


1 comment:

  1. Hi there, i am implementing the same code as yours in Microsoft Dynamics CRM 2016 on prem but no change occurs in the views. could you please help me out? thanks

    ReplyDelete

Note: Only a member of this blog may post a comment.