
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:55 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:11 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:17 AM
@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.
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:17 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 12:49 PM