Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Alon Grod 

use this in UI action condition

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Sandeep Rajput
Tera Patron
Tera Patron

@Alon Grod Please try the following in the condition field of the UI Action.

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

Anand Kumar P
Giga Patron

Hi @Alon Grod ,

Use below condition

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

Thanks,

Anand

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