web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / hide specific controls...
Power Pages
Answered

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

(0) ShareShare
ReportReport
Posted on by 92

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


Categories:
  • Verified answer
    oliver.rodrigues Profile Picture
    9,482 Most Valuable Professional on at

    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.

  • Verified answer
    JisungHan Profile Picture
    Microsoft Employee on at

    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/client-scripting 

     

     

    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-utility/getglobalcontext/usersettings#securityroles

     

    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/setvisible 

     

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

     

    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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Pages

#1
Mohsin Ali Profile Picture

Mohsin Ali 35

#2
M Bilal Khan Profile Picture

M Bilal Khan 33

#3
11manish Profile Picture

11manish 21 Super User 2026 Season 2

Last 30 days Overall leaderboard