I want to hide a button (UI Action) from users with a certain role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 01:50 PM
In the condition of the UI Action, I currently have the following code: current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList()
I would like to keep anyone who has the role of auditor from seeing this UI Action (button), so I added: && !gs.hasRole('auditor')
The entirety of the condition is now: current.canCreate() && !RP.getListControl().isOmitNewButton() && !RP.isRelatedList() && !gs.hasRole('auditor')
I assumed that this would mean, that for a user to see this, they would have to not have the role of auditor. But when I impersonate an auditor, I still see the button.
What am I doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 11:04 AM
I did that, now everyone can see that button, except for the admin.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 10:48 PM
print all the condition in the ui action ... like paste this in your ui action....
gs.addInfoMessage(current.canCreate());
gs.addInfoMessage(!RP.getListControl().isOmitNewButton());
gs.addInfoMessage(!RP.isRelatedList());
gs.addInfoMessage(!gs.hasRole('auditor'));
find your culprit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 10:23 AM
Thanks. It works when I log in as admin as well as when I impersonate an ITIL user, but when I impersonate an auditor, it doesn't return anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 11:57 PM
Hi Eric,
try below code onLoad script of your table
items = $$('BUTTON').each(function(item){
if(item.innerHTML.indexOf('Process Request') > -1){
// verify the UI action name here ' Process Request is a name of my UI action button
var grMember1 = new GlideRecord('sys_user_grmember');
grMember1.addQuery('user', g_user.userID);
grMember1.addQuery('group', 'a96ad9e698b9d000d511c2c579ca7054'); // sys_id of role
grMember1.query();
if (grMember1.next()) {
item.show();
}
else {
item.hide();
}
you may need some minor changes here
Hope this helps.
Thanks,
Abhijeet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2014 10:49 AM
I tried the following but get an unmatched '{' on line 2.
So, I tried putting a matching bracket at the very bottom of the script and got the error ERROR at line 16: Expected ')' and instead saw ''. I've tried putting a matching bracket where I think it would be appropriate and I just get more errors.
function onLoad() {
items = $$('BUTTON').each(function(item){
if(item.innerHTML.indexOf('New') > -1){
// verify the UI action name here ' Process
var grMember1 = new GlideRecord('sys_user_grmember');
grMember1.addQuery('user', g_user.userID);
grMember1.addQuery('group', 'a96ad9e698b9d000d511c2c579ca7054'); // sys_id of role
grMember1.query();
if (grMember1.next()) {
item.show();
}
else {
item.hide();
}
}