- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 03:29 AM
I need to create a new UI Action on the incident form (a button). The button needs to be displayed only when these conditions are met:
1) the login user is 'admin'
OR
2. the login user is a member of the current assignment group
OR
3. the login user is a member of the parent's group of the current assignment group.
I tried to use these conditions:
gs.hasRole('admin') || gs.getUser().isMemberOf(current.assignment_group.name) || gs.getUser().isMemberOf(current.assignment_group.parent.name)
The problem is that Im able to see the UI Action whenever the assignment group is my group's parent and whenever the assignment group has the same group's parent like I have.
For example,
If i belong to 'Software' group and my group's parent is 'Computers'. When the assignment group on the incident is 'Computers' Im not supposed to see the UI Action (but right now I do see). In addition, if the assignment group is 'Hardware' and we share the same group's parent ('Computers'), Im not suppose to see the UI Action. But if I belong to 'Computers' i suppose to see the UI Action whenever the assignment group is on of my Childs or the group itself.
What do I need to change?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 04:24 AM - edited 10-29-2023 04:25 AM
Hi @Alon Grod ,
I would recommend using a script include for this
You can add it to your UI Action condition for example, javascript: new IsMemberOf().CheckMembership();
And your script include could be something like this:
var IsMemberOf = Class.create();
IsMemberOf.prototype = {
initialize: function() {},
CheckMembership: function(){
if(gs.hasRole('admin')){
return true;
}
var user = gs.getUserID();
var member = new GlideRecord('sys_user_grmember');
member.addQuery('user',user);
member.query();
while(member.next()){
if(member.group == current.assignment_group){
return true;
}
if(member.group == current.assignment_group.parent){
return true;
}
}
return false;
},
type: 'IsMemberOf'
};
If that works for you please mark my answer as correct/ helpful 🙂
Let me know if can I help you further
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 04:17 AM
Hello @Alon Grod
Try using the AND Operator between 2nd and 3rd Operator.
gs.hasRole('admin') || gs.getUser().isMemberOf(current.assignment_group.name) && gs.getUser().isMemberOf(current.assignment_group.parent.name)
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 04:45 AM
@Samaksh Wani still not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2023 04:24 AM - edited 10-29-2023 04:25 AM
Hi @Alon Grod ,
I would recommend using a script include for this
You can add it to your UI Action condition for example, javascript: new IsMemberOf().CheckMembership();
And your script include could be something like this:
var IsMemberOf = Class.create();
IsMemberOf.prototype = {
initialize: function() {},
CheckMembership: function(){
if(gs.hasRole('admin')){
return true;
}
var user = gs.getUserID();
var member = new GlideRecord('sys_user_grmember');
member.addQuery('user',user);
member.query();
while(member.next()){
if(member.group == current.assignment_group){
return true;
}
if(member.group == current.assignment_group.parent){
return true;
}
}
return false;
},
type: 'IsMemberOf'
};
If that works for you please mark my answer as correct/ helpful 🙂
Let me know if can I help you further
Cheers