How to hide approve button based on role in service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @vivek11 ,
You can clone the widget and find client controller and inside the client controller, add an if statement to check for the user's roles using the gs.hasRole("<role_name>") script. Set the button's visibility to false if the user does not have the required role. For example:
JavaScript
// Example in Client Controller
if (!gs.hasRole("<<!nav>>your_role_here<<!/nav>>")) {
// Assuming 'c.showApprove' controls the button's visibility
c.showApprove = false;
}
Regards,
Nikhil Bajaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
but why?
If you hide then how approver will Approve?
I will recommend to discuss this requirement with your customer.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @vivek11
If it's a UI Action button, control visibility via the Condition on UI Action( Simplest & Secure)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
@vivek11 There are few things which you need to understand here, I have checked the code in the widget.
- gs.hasRole() will not work in client controller as it is server side code and on top of that it is not recommended to customise the widget.
- There is no specific ng-if in the widget "Todos Approval Actions" for approval button, ng-if controls the entire approval section.
- ng-if is controlled by a OOB Script include "TodoApprovalActionsUtilSNC" and function "isApprover".
- The script include function checks if you are approver of record and you have write access to Approval state. So now , you need to check the ACL "sysapproval_approver.state".
- ACL "sysapproval_approver.state" gives access to users with "approval_admin" role or if user is requested for of approval record or delegate of requested for.
- So you can add your condition in this ACL to show hide the approval section, but hiding approval button without customising is not possible.
I hope this clarifies.
Raghav
MVP 2023