The CreatorCon Call for Content is officially open! Get started here.

UI Action Condition to being display

Alon Grod
Tera Expert

Hi,

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'.

2. the login user is a member of the current assignment group

3. the login user  is a member of the parent's group of the current assignment group.

How can I achieve that? What should I type for the condition tab?


1 ACCEPTED SOLUTION

Shivam Techlene
Tera Guru

Hello @Alon Grod ,

 

You can utilize the script given below under the condition field of UI action form:

 

NOTE: your UI action should be in the global scope to work properly as "gs.getUser().isMemberOf" doesn't give desired result inside scoped applications.

!current.assignment_group.nil() && gs.hasRole('admin') && gs.getUser().isMemberOf(current.assignment_group.name) && gs.getUser().isMemberOf(current.assignment_group.parent.name)

 

In the above code, I've added one more condition to check empty assignment group field. But one thing I noticed that users with "admin" role automatically becomes member of the parent group of their respective group. For example: I have a user "XYZ" and he's an admin and also member of "Analyst" group, which is child of "Architects" group. But when I check in the background script that "XYZ" is a member of "Architects" group or not, it return true!

Although Servicenow Documentation suggests opposite:

"Parent: Other group of which this group is a member. The child group inherits the roles of the parent group. So, if a group has a parent, it inherits the roles of the parent group. However, the members of the child group are not members of the parent group."

Kindly Refer to https://developer.servicenow.com/dev.do#!/learn/learning-plans/tokyo/new_to_servicenow/app_store_lea...  for more information about groups.

 

Kindly Mark my answer helpful and correct if it solves your question and helps you to understand the scenario better.

 

Tyhanks & Regards,

Shivam Jaiswal

 

Thanks & Regards,
Shivam Jaiswal

View solution in original post

9 REPLIES 9

Hi @Alon Grod,

 

Any updates on this?

Were you able to utilize my answer to reproduce the requirement?

Kindly mark my answer helpful and correct if it helps to fulfill your requirement or helps you gaining knowledge to achieve it.

 

Thanks & Regards,

Shivam Jaiswal

Thanks & Regards,
Shivam Jaiswal

@Shivam Techlene 

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?

Hello @Alon Grod ,

 

You are using OR condition. It should be AND condition here. Script given below is working for me exactly as per your requirement.

 

There are three OOTB groups in servicenow Database, Database Altanta & Database San Diego. And "Database" is the parent group of other two groups. My user is part of "Database Atlanta" and the UI action is only showing to me when the assignment group on the incidents is "Database Atlanta" . And not showing when the assignment group is "Database" & "Database San Diego".

!current.assignment_group.nil() && gs.hasRole('admin') && gs.getUser().isMemberOf(current.assignment_group.name) &&  gs.getUser().isMemberOf(current.assignment_group.parent.name)

Kindly try to use this one.

 

Thanks & Regards,

Shivam Jaiswal

Thanks & Regards,
Shivam Jaiswal

Hello @Alon Grod ,

 

Any updates on this one?

 

Kindly mark it helpful if it resolves your issue.

Thanks & Regards,
Shivam Jaiswal

Hello @Alon Grod ,

 

Did you get a chance to try this one?

Please mark it helpful and correct if it resolved your query.

 

Thanks & Regards,
Shivam Jaiswal