cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

hide specific controls of Contact entity for specific users and show all to Admin user.

Hi Team,

I want to hide some controls or fields of contact entity to specific users and want to show all to Admin users.

Example:
Show City on Portal profile page for users other than Admin.
And show all like City , Name, Zip Code to admin

Is there any way to manage this requirement?

Thanks,
Vaibhav


2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User II
Super User II

Hi

 

If you want to achieve that via JS, you can see the roles via JS and show/hide fields

this code gets the user roles

$(document).ready(function () {
    var roles = "{{ user.roles }}";
    var isAdmin = "{{ user | has_role: 'Administrators' }}"
    console.log("Is Admin: " + isAdmin);
    console.log("User Roles: " + roles);
});

Take a look at this post if you need the code to hide/show fields: http://oliverrodrigues365.com/2020/07/19/power-apps-portals-javascript-tip-01-hide-show-elements/

 

that's if you want to do via JS, take in consideration that this is not the most secure way, as a user could display the fields via browser dev tools, or even disable JS on the browser

if you want to achieve that in a more secure way, I would suggest the following:

  • Duplicate your components - Web Pages / Entity Form / CDS Form, etc
  • Create a Web Page Control Access Rule for the "admin" page, allowing only admin users to access that page

 

hope this helps

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

Microsoft
Microsoft

Hi @VSJadhav ,

 

If you use the PowerApps for Portal, you may use @OliverRodrigues 's suggestion to check the role when the page loads.

 

If you want to add this feature in a entity form of model-driven app on Common Data Service environment, use the following Javascript with Client API:

1. Client scripting in Customer Engagement using Javascript: https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/clientapi/clie... 

 

 

2. Events in forms and grids in model-driven apps: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/events-forms-grids 

 

In the #2, you may choose Form > onLoad as below

JisungHan_0-1602231245929.png

 

3. Using "userSettings.securityRoles" method, catch up the System admin security role GUID:

userSettings.securityRoles: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utili...

 

4. Using "setVisible" method, set the visibility of the fields

 

setVisible: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/... 

 

5. Walkthrough: Write your first client script: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/walkthrough-write-y...

 

If you are not familiar with the Form scripting in CDS environment, please refer to the #5 walkthrough.

 

Hope this helps. Thanks!

 

Best regards,
Jisung Han

View solution in original post

2 REPLIES 2
Super User II
Super User II

Hi

 

If you want to achieve that via JS, you can see the roles via JS and show/hide fields

this code gets the user roles

$(document).ready(function () {
    var roles = "{{ user.roles }}";
    var isAdmin = "{{ user | has_role: 'Administrators' }}"
    console.log("Is Admin: " + isAdmin);
    console.log("User Roles: " + roles);
});

Take a look at this post if you need the code to hide/show fields: http://oliverrodrigues365.com/2020/07/19/power-apps-portals-javascript-tip-01-hide-show-elements/

 

that's if you want to do via JS, take in consideration that this is not the most secure way, as a user could display the fields via browser dev tools, or even disable JS on the browser

if you want to achieve that in a more secure way, I would suggest the following:

  • Duplicate your components - Web Pages / Entity Form / CDS Form, etc
  • Create a Web Page Control Access Rule for the "admin" page, allowing only admin users to access that page

 

hope this helps

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

Microsoft
Microsoft

Hi @VSJadhav ,

 

If you use the PowerApps for Portal, you may use @OliverRodrigues 's suggestion to check the role when the page loads.

 

If you want to add this feature in a entity form of model-driven app on Common Data Service environment, use the following Javascript with Client API:

1. Client scripting in Customer Engagement using Javascript: https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/clientapi/clie... 

 

 

2. Events in forms and grids in model-driven apps: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/events-forms-grids 

 

In the #2, you may choose Form > onLoad as below

JisungHan_0-1602231245929.png

 

3. Using "userSettings.securityRoles" method, catch up the System admin security role GUID:

userSettings.securityRoles: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utili...

 

4. Using "setVisible" method, set the visibility of the fields

 

setVisible: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/... 

 

5. Walkthrough: Write your first client script: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/walkthrough-write-y...

 

If you are not familiar with the Form scripting in CDS environment, please refer to the #5 walkthrough.

 

Hope this helps. Thanks!

 

Best regards,
Jisung Han

View solution in original post

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Users online (32,622)