Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Need to hide all views for the entity except one for a particular user.

Posted on by 814

Hi,

I want to show only one view to a user and want to hide all other views from one user on work order entity. At present i have 10-14 views under this entity.

Do anyone has any idea on how to do this?

I do not want to purchase rolebasedview, so if anyone has any idea, do let us know.

*This post is locked for comments

  • Abhilash M abi Profile Picture
    Abhilash M abi 595 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Kokulan  Can you please suggest me how can i achieve the same in UCI. Stuck with same requirement.

  • Ravi Fulani Profile Picture
    Ravi Fulani 814 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Hi,

    We have upgraded to UCI, please let me know what changes we should implement in order to achieve the desired functionality.

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Need to hide all views for the entity except one for a particular user.

    You could try something like the following

               if (!userRoleFound)

               {

                   // Non Sys admin users

                   if (context.UserId == new Guid("8B719799-5A49-4DB0-8157-415FB21A4186"))  // Particular User's ID, you could create method to get the user by name as well

                   {

                       ConditionExpression c = new ConditionExpression("name", ConditionOperator.In, new object[] { "View1", "View2", "View2" });

                       qe.Criteria.Conditions.Add(queryCondition);

                   }

                   else

                   {

                       // For all other users

                       ConditionExpression queryCondition = new ConditionExpression("name", ConditionOperator.Equal, "Authorized Contact");

                       qe.Criteria.Conditions.Add(queryCondition);

                   }

               }

  • Ravi Fulani Profile Picture
    Ravi Fulani 814 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Can you help me further with this query as i have extended my question

  • Ravi Fulani Profile Picture
    Ravi Fulani 814 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Hi there, thanks. It seems that xml code seems working, although I do need little understanding of this query. But for now all ok. I do want to ask what if to particular user I just need to show 3 views.

    I Tried repeating this

       {

                                           ConditionExpression queryCondition = new ConditionExpression("name", ConditionOperator.Equal, "Authorized Contact");

                                           ConditionExpression queryCondition1 = new ConditionExpression("name", ConditionOperator.Equal, "Authorized User IDs");

                                           qe.Criteria.Conditions.Add(queryCondition);

                                           qe.Criteria.Conditions.Add(queryCondition1);

                                       }

    The one view which i was able to see that also stopped working.

    I also tried via making object

    string[] values = new string[] { "Value1", "Value2" };
    ConditionExpression cond = new ConditionExpression("name", ConditionOperator.In, values);

    qe.Criteria.Conditions.Add(cond);

    and 

    string[] values = new string[] { "Value1", "Value2" }object value = values;
    ConditionExpression c = new ConditionExpression("name", ConditionOperator.In, value);

    and it also not seems to working.

     is there any other way via which I can do.

    Thank you so much for help.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Hi

    There are few ways to do this, since I used Dynamics 365 Developer Toolkit, I do the following to register the plugin on SavedQuery entity.

    https://marketplace.visualstudio.com/items?itemName=DynamicsCRMPG.MicrosoftDynamicsCRMDeveloperToolkit

    4274.ScreenClip-_5B00_174_5D00_.png

    And in the Primary entity field, if i start searching for Saved query, you can see its available

    4274.ScreenClip-_5B00_174_5D00_.png

    Note : I forgot to mention, your plugin code example will only work for classic UI, for it to work on UCI, changes will have to be made. Let me know if you want this to work on UCI

  • Ravi Fulani Profile Picture
    Ravi Fulani 814 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Hi There,

    I got the code, but as I want to hide all views on my work order entity, I thought that plugin should be created on Work order entity but as now as i have seen few links, many have made the plugin on savedquery. And I don't see this entity in my CRM can you please tell me what step I should take?

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Well, that was open source and its old version but still free for use I think but your plugin is a better solution as you have full control over and its lightweight so I would recommend you stick with plugin approach.

    I have had a look your plugin code, please see my feedback/suggestions below

    You only want to display the Authorised Contact view if the user is not sys admin, so you may want to change the condition as shown below

                                       string roleName = "System Administrator";

                                       bool userRoleFound = VerifyIfUserHasRole(roleName, context.UserId, crmService);

                                       if (!userRoleFound)

                                       {

                                           ConditionExpression queryCondition = new ConditionExpression("name", ConditionOperator.Equal, "Authorized Contact");

                                           qe.Criteria.Conditions.Add(queryCondition);

                                       }

    And you could also the VerifyIfUserHasRole to the following, just to get rid of FETCH XML

    public bool VerifyIfUserHasRole(string roleName, Guid userId, IOrganizationService crmService)

               {

                   var QEsystemuser = new QueryExpression("systemuser");

                   QEsystemuser.Distinct = true;

                   QEsystemuser.ColumnSet.AddColumns("fullname", "systemuserid");

                   var QEsystemuser_systemuserroles = QEsystemuser.AddLink("systemuserroles", "systemuserid", "systemuserid");

                   var QEsystemuser_systemuserroles_role = QEsystemuser_systemuserroles.AddLink("role", "roleid", "roleid");

                   QEsystemuser_systemuserroles_role.EntityAlias = "aa";

                   QEsystemuser_systemuserroles_role.LinkCriteria.AddCondition("name", ConditionOperator.Equal, roleName);

                   return crmService.RetrieveMultiple(QEsystemuser).Entities.Count > 0;

               }

  • Ravi Fulani Profile Picture
    Ravi Fulani 814 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Is there some license for this, Do we have to purchase this? I don't want to purchase it. IS writing the plugin is last option? I am thinking of editing the attached code.code-for-plugin.txt

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Need to hide all views for the entity except one for a particular user.

    Hi

    You could look into controlling the views using the following third-party tool. Please note that the tool is not maintained by the dev on this site but it should work

    www.powerobjects.com/.../assigning-system-views-based-security-roles-dynamics-crm

    archive.codeplex.com

    If you do not like to use the third party solution, you may end up creating a retrieve multiple plugin on Saved Query to filter the list of views returned based on the current user.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans