How to hide approve button based on role in service portal

vivek11
Tera Contributor

vivek11_0-1757247473024.png

 

9 REPLIES 9

Nikhil Bajaj9
Giga 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

Ankur Bawiskar
Tera Patron
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

NayeemSk
Giga Contributor

Hi @vivek11 

 

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

RaghavSh
Kilo 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.


Raghav
MVP 2023