Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to hide approve button based on role in service portal

vivek11
Tera Contributor

vivek11_0-1757247473024.png

 

10 REPLIES 10

Nikhil Bajaj9
Tera Sage

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;
    }

 

 

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

ServiceNow Rising Star-2025

Ankur Bawiskar
Tera Patron

@vivek11 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

NayeemSk
Tera Contributor

Hi @vivek11 

 

If it's a UI Action button, control visibility via the Condition on UI Action( Simplest & Secure)

Raghav Sharma24
Giga Patron

@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.