UI Action needed to restrict a user with the proper role or sysid.

KKrabbenhoft
Tera Guru

Hi there my fellow developers!

 

I have a business need to hide the "create problem" UI Action in a context menu from users other than the person with a specific role. I have tried several times to write a script in my ui action but the user can still select " create problem" from the context menu. Here is my code. 

(function() {
var user = g_user.getUserName(); // Get the current user's username
if (user === 'specific_user') {
// Hide the context menu option
g_form.removeOption('create_problem');
}
})();

This does not work 

 

3 ACCEPTED SOLUTIONS

Robbie
Kilo Patron
Kilo Patron

Hi @KKrabbenhoft,

 

Within a UI Action there is a condition field. The conditions need to be met in order for the UI action to be visible as well as actionable.

 

Referencing the Out Of The Box 'Create Problem' UI Action on the Incident table, you'll notice the following syntax:

gs.hasRole("itil,sn_problem_write")

This essentially means you must have one of these roles in order to view and action the functionality.

(You can also inverse this by stating you must not have a certain role. Eg !gs.hasRole("given_role")

 

Can you not adjust this (or copy for your UI action) appropriately for your needs? This is exactly what the condition field is for.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

Screenshot 2024-04-03 at 18.06.39.png

 

View solution in original post

Sandeep Rajput
Tera Patron
Tera Patron

@KKrabbenhoft To hide a UI Action you need to use condition field of the UI Action to hide the UI Action if the condition returns false;

 

Here is an example.

 

Screenshot 2024-04-03 at 10.45.59 PM.png

 

Here is the example condition

 !gs.hasRole('itil') || !gs.getUserID()=='2f43c471c0a8006400a07440e49924c2'

Replace itil with the role you would like to check and sys_id with the sys_id with the sys_id of the user.

 

View solution in original post

KKrabbenhoft
Tera Guru

Thank you for the quick response @Robbie . We will give it a shot. you rock!!!

View solution in original post

6 REPLIES 6

KKrabbenhoft
Tera Guru

Thank you for the quick response @Robbie . We will give it a shot. you rock!!!

Hi @KKrabbenhoft,

 

No worries, glad I could help.

 

Cheers, Robbie