- 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
Try this code:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I think the core issue with the script lies in this specific line: if (group.type == 'Test Integration User') {
This will always evaluate to false in ServiceNow for two distinct reasons:
getReference returns raw database values (Sys IDs): When you use getReference on the client side, the object it returns contains the raw database values, not the string display values. group.type will return a 32-character Sys ID, not the string "Test Integration User".
The Type field is a List (glide_list), not a single Reference: A group can have multiple types (e.g., "ITIL", "Agile", "Test Integration User"). Because it is a list field, group.type will actually return a comma-separated string of Sys IDs (e.g., sys_id_1,sys_id_2,sys_id_3).
Comparing a comma-separated list of Sys IDs to the string 'Test Integration User' will always fail, meaning the category and subcategory will never become mandatory.
This will not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @namanajain ,
Thanks for your quick response.
Working on normal incident form.
We already try the above script by adding log also but it's' not working every time it comes under the else part.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @adityaashok
The main problem is that assignment group provide name with spacing so it evaluates false every time
Use instead :- g_form.getDisplayValue('assignment_group').trim()
