- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello Community,
We have the following requirement:
When creating an Incident, if the Assignment Group type is “Test Integration User”, then Category and Subcategory must be mandatory.
If the Assignment Group is changed later and the new group does not belong to our scope (i.e., it is not of type Test Integration User), then Category and Subcategory should no longer be mandatory.
We attempted to implement this using UI Policies, Catalog Client Scripts, and UI Policy script actions, but none of these approaches worked as expected.
Can anyone help me on this?
Thanks!!
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @adityaashok ,
This is a great requirement, but it is a classic ServiceNow "gotcha." The reason standard UI Policies, Catalog Client Scripts, and the getReference method fail here is due to the architecture of the Type field on the Group (sys_user_group) table.
The type field is a List field (glide_list), meaning a single group can have multiple types (e.g., ITIL, Agile, Test Integration User). Because it is a list of references, trying to read it on the client side usually returns a comma-separated string of 32-character Sys IDs, not the display names. Therefore, simple string comparisons like group.type == 'Test Integration User' will always evaluate to false.
The strictest, most reliable best practice to solve this is to use an Asynchronous GlideAjax call. This asks the server to evaluate the list field safely and return a simple true/false to the form.
Here is the step-by-step solution:
1. Create the Script Include (Server-Side)
This script securely checks the group's type without exposing raw Sys IDs to the client.
Name: GroupTypeAjax
Client callable: Check the box (Very Important!)
Script:
var GroupTypeAjax = Class.create(); GroupTypeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, { checkGroupType: function() { var groupId = this.getParameter('sysparm_group_id'); var targetType = 'Test Integration User'; // Ensure this matches your exact Type name if (!groupId) { return 'false'; } var groupGr = new GlideRecord('sys_user_group'); if (groupGr.get(groupId)) { // getDisplayValue gets the comma-separated string of names, avoiding Sys IDs var typeDisplay = groupGr.getDisplayValue('type'); if (typeDisplay && typeDisplay.indexOf(targetType) > -1) { return 'true'; } } return 'false'; }, type: 'GroupTypeAjax' });
2. Create the Client Script (Client-Side)
This script runs when the Assignment Group changes, calls the Script Include, and updates the form based on the answer.
Table: Incident [incident]
Type: onChange
Field name: Assignment group
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading) { return; } // If the group is cleared out, remove the mandatory requirement if (newValue === '') { g_form.setMandatory('category', false); g_form.setMandatory('subcategory', false); return; } // Call the server to check the group type var ga = new GlideAjax('GroupTypeAjax'); ga.addParam('sysparm_name', 'checkGroupType'); ga.addParam('sysparm_group_id', newValue); // Process the true/false response asynchronously ga.getXMLAnswer(function(response) { if (response === 'true') { g_form.setMandatory('category', true); g_form.setMandatory('subcategory', true); } else { g_form.setMandatory('category', false); g_form.setMandatory('subcategory', false); } }); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
hi @adityaashok
You can easily configure this using onchange client script or ui policies, just check other client script is not blocking your ui policy actions.. meanwhile please try this
Use the filterr to dot walk to the group type.
Show related fields
Assignment group ->Type [contains] Test Integration User
Reverse if false = true
UI Policy Actions:
category: Mandatory = True
subcategory: Mandatory = True
Happy to help!
To help others in the community find this solution, kindly mark this response as the Correct Answer and Helpful.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @adityaashok ,
This is a great requirement, but it is a classic ServiceNow "gotcha." The reason standard UI Policies, Catalog Client Scripts, and the getReference method fail here is due to the architecture of the Type field on the Group (sys_user_group) table.
The type field is a List field (glide_list), meaning a single group can have multiple types (e.g., ITIL, Agile, Test Integration User). Because it is a list of references, trying to read it on the client side usually returns a comma-separated string of 32-character Sys IDs, not the display names. Therefore, simple string comparisons like group.type == 'Test Integration User' will always evaluate to false.
The strictest, most reliable best practice to solve this is to use an Asynchronous GlideAjax call. This asks the server to evaluate the list field safely and return a simple true/false to the form.
Here is the step-by-step solution:
1. Create the Script Include (Server-Side)
This script securely checks the group's type without exposing raw Sys IDs to the client.
Name: GroupTypeAjax
Client callable: Check the box (Very Important!)
Script:
var GroupTypeAjax = Class.create(); GroupTypeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, { checkGroupType: function() { var groupId = this.getParameter('sysparm_group_id'); var targetType = 'Test Integration User'; // Ensure this matches your exact Type name if (!groupId) { return 'false'; } var groupGr = new GlideRecord('sys_user_group'); if (groupGr.get(groupId)) { // getDisplayValue gets the comma-separated string of names, avoiding Sys IDs var typeDisplay = groupGr.getDisplayValue('type'); if (typeDisplay && typeDisplay.indexOf(targetType) > -1) { return 'true'; } } return 'false'; }, type: 'GroupTypeAjax' });
2. Create the Client Script (Client-Side)
This script runs when the Assignment Group changes, calls the Script Include, and updates the form based on the answer.
Table: Incident [incident]
Type: onChange
Field name: Assignment group
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading) { return; } // If the group is cleared out, remove the mandatory requirement if (newValue === '') { g_form.setMandatory('category', false); g_form.setMandatory('subcategory', false); return; } // Call the server to check the group type var ga = new GlideAjax('GroupTypeAjax'); ga.addParam('sysparm_name', 'checkGroupType'); ga.addParam('sysparm_group_id', newValue); // Process the true/false response asynchronously ga.getXMLAnswer(function(response) { if (response === 'true') { g_form.setMandatory('category', true); g_form.setMandatory('subcategory', true); } else { g_form.setMandatory('category', false); g_form.setMandatory('subcategory', false); } }); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @Yogesh11bhatt ,
This is working fine.
Thanks for your quick response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @adityaashok
This code will work
