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
Solved! Go to Solution.
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:
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.
Power Apps Portals Super User
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
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
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:
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.
Power Apps Portals Super User
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
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
User | Count |
---|---|
9 | |
8 | |
6 | |
4 | |
2 |
User | Count |
---|---|
28 | |
26 | |
26 | |
22 | |
6 |