Script include for ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2024 04:46 AM
Hi all,
I have one requirement
1.
when the user having the "abc" role then the assignment group also having the same role then only user can able to see the escalation UI action , i have write the script for that , it's working bit when i m impersonating the user who having the "abc" role & the assignment group doesn't having the role even though they can able to see the ui action , how can i restrict when the group doesn't have the role?
checkActionableUIActionVisibility: function(sirRecord) {
if (gs.hasRole('abc')) {
var userSysId = gs.getUserID();
if (sirRecord.assignment_group && sirRecord.assignment_group == gs.getUser().getGroupID()) {
return true;
} else if (sirRecord.assigned_to && sirRecord.assigned_to == userSysId) {
return true;
}
}
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2024 05:35 AM
Hi @DeepikaR1661877 Try below code
checkActionableUIActionVisibility: function(sirRecord) {
var userSysId = gs.getUserID();
var userHasRole = gs.hasRole('abc');
if (!userHasRole) {
return false;
}
var groupHasRole = false;
if (sirRecord.assignment_group) {
var groupSysId = sirRecord.assignment_group;
var grGroup = new GlideRecord('sys_user_group');
if (grGroup.get(groupSysId)) {
var grGroupRoles = new GlideRecord('sys_group_has_role');
grGroupRoles.addQuery('group', groupSysId);
grGroupRoles.addQuery('role.name', 'abc');
grGroupRoles.query();
if (grGroupRoles.next()) {
groupHasRole = true;
}
}
}
if (groupHasRole) {
if (sirRecord.assignment_group && sirRecord.assignment_group == gs.getUser().getGroupID()) {
return true;
} else if (sirRecord.assigned_to && sirRecord.assigned_to == userSysId) {
return true;
}
}
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2024 07:13 AM
Hi @Sid_Takali ,
I have tried above scripts it's not working when i am impersonate the user and the assignment group doesn't have the "abc" role but i can able to see the UI action, any condition needs to provide in the UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2024 07:50 AM
Hi @DeepikaR1661877
The issue lies in how you are checking the assignment group. In your script, you’re only checking if the current user’s group matches the assignment group, but not whether the group actually has the "abc" role. Additionally, you should verify if the assignment group has the required role before showing the UI action.
Code:-
checkActionableUIActionVisibility: function(sirRecord) {
if (gs.hasRole('abc')) {
var userSysId = gs.getUserID();
if (sirRecord.assignment_group) {
var groupGr = new GlideRecord('sys_user_grmember');
groupGr.addQuery('group', sirRecord.assignment_group);
groupGr.addQuery('user.active', true);
groupGr.addQuery('user.sys_id', 'IN', gs.getUser().getUserByRole('abc'));
groupGr.query();
if (groupGr.hasNext()) {
if (sirRecord.assignment_group == gs.getUser().getGroupID() || sirRecord.assigned_to == userSysId) {
return true;
}
}
}
}
return false;
}
If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.
Regards,
Manoj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2024 09:30 PM
Hi @Manoj R Zete ,
When i am using the above script it's not working, in that incident table it will show the few record only, when i am open the any record assignment group doesn't have the role even though they can able to see the UI action, no need to restrict the table record, need to hide the ui action when the current logged in user having the "abc" role and group doesn't have.