- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 09:19 PM
Hi all,
I have a choice field on the Incident form called Group Type with values: Group A, Group B, Group C.
I also have the Assignment Group field, which is a reference to the Group table.
I want to filter the Assignment Group options so that when I select, for example, Group A in the Group Type field, the Assignment Group field should only show groups of type A.
What’s the best way to do this? Should I use a client script or reference qualifier?
Any sample script or best practice approach would be really helpful.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 11:50 PM
Hi @Community Alums ,
I have created one field on incident table with choices as Group A , Group B etc
There is one field on Group[sys_user_group] table with name Type which is 'List' type of field and is reference to sys_user_group_type table . So , I have created two records in it with name GroupA and GroupB
Now , i have given these type to certain groups
I have created one script include as below
Below is the script for your reference
/**
* Script Include: GroupTypeFilter
*
* Purpose
* -------
* Given a record (e.g. an Incident) that has the choice field `u_group_type`,
* return an encoded qualifier such as
*
* sys_idIN05d9ad9ceb9982d482a0fb93dad0cdaf,68efd14cdb2dc30083ab852b0b9619d
*
* That string can be placed directly in a Reference Qualifier for
* the **Assignment Group** field so only the desired groups appear.
*
* Usage
* -----
* In the *Assignment Group* dictionary entry → Reference qualifier:
*
* javascript:new GroupTypeFilter ().getQualifier(current)
*/
var GroupTypeFilter = Class.create();
GroupTypeFilter.prototype = {
initialize: function() {},
/**
* Build the “sys_idIN” qualifier.
*
* @param {GlideRecord} current – the record whose Group Type was chosen
* @return {String} – qualifier or empty string if none
*/
getQualifier: function(current) {
/* 1️⃣ Map choice ➜ one or more Group‑Type sys_ids */
var choice = current.getValue('u_group_type'); // e.g. 'group_a'
var typeIdsByChoice = {
group_a: ['21a9dfb9c3266a104f59190ed401310f'], // Group A - Use Property to store sys_ids instead of hardcoding
group_b: ['bdb91bb9c3266a104f59190ed40131e8'] // Group B
};
var typeIds = typeIdsByChoice[choice];
if (!typeIds) // nothing selected → no filtering
return '';
/* 2️⃣ Collect the sys_ids of groups whose *type* list contains any of those IDs */
var grp = new GlideRecord('sys_user_group');
grp.addActiveQuery();
// Build an OR query: type = id1 OR type = id2 …
var qc = grp.addQuery('type', typeIds[0]);
for (var i = 1; i < typeIds.length; i++)
qc.addOrCondition('type', typeIds[i]);
var ids = [];
grp.query();
while (grp.next())
ids.push(grp.getUniqueValue());
/* 3️⃣ Return the qualifier */
return ids.length ? 'sys_idIN' + ids.join(',') : '';
},
type: 'GroupTypeFilter'
};
I have called this script include in dictionary of assignment group as below
Result :
There are two groups in my instance where type is Group A . So, now only those groups will be visible in Assignment group field
If my answer helped you, please consider marking it as ✅ Correct and giving it a 👍 Helpful — it might help other members in the community too!
Thanks,
Astik T 😊💡
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 11:50 PM
Hi @Community Alums ,
I have created one field on incident table with choices as Group A , Group B etc
There is one field on Group[sys_user_group] table with name Type which is 'List' type of field and is reference to sys_user_group_type table . So , I have created two records in it with name GroupA and GroupB
Now , i have given these type to certain groups
I have created one script include as below
Below is the script for your reference
/**
* Script Include: GroupTypeFilter
*
* Purpose
* -------
* Given a record (e.g. an Incident) that has the choice field `u_group_type`,
* return an encoded qualifier such as
*
* sys_idIN05d9ad9ceb9982d482a0fb93dad0cdaf,68efd14cdb2dc30083ab852b0b9619d
*
* That string can be placed directly in a Reference Qualifier for
* the **Assignment Group** field so only the desired groups appear.
*
* Usage
* -----
* In the *Assignment Group* dictionary entry → Reference qualifier:
*
* javascript:new GroupTypeFilter ().getQualifier(current)
*/
var GroupTypeFilter = Class.create();
GroupTypeFilter.prototype = {
initialize: function() {},
/**
* Build the “sys_idIN” qualifier.
*
* @param {GlideRecord} current – the record whose Group Type was chosen
* @return {String} – qualifier or empty string if none
*/
getQualifier: function(current) {
/* 1️⃣ Map choice ➜ one or more Group‑Type sys_ids */
var choice = current.getValue('u_group_type'); // e.g. 'group_a'
var typeIdsByChoice = {
group_a: ['21a9dfb9c3266a104f59190ed401310f'], // Group A - Use Property to store sys_ids instead of hardcoding
group_b: ['bdb91bb9c3266a104f59190ed40131e8'] // Group B
};
var typeIds = typeIdsByChoice[choice];
if (!typeIds) // nothing selected → no filtering
return '';
/* 2️⃣ Collect the sys_ids of groups whose *type* list contains any of those IDs */
var grp = new GlideRecord('sys_user_group');
grp.addActiveQuery();
// Build an OR query: type = id1 OR type = id2 …
var qc = grp.addQuery('type', typeIds[0]);
for (var i = 1; i < typeIds.length; i++)
qc.addOrCondition('type', typeIds[i]);
var ids = [];
grp.query();
while (grp.next())
ids.push(grp.getUniqueValue());
/* 3️⃣ Return the qualifier */
return ids.length ? 'sys_idIN' + ids.join(',') : '';
},
type: 'GroupTypeFilter'
};
I have called this script include in dictionary of assignment group as below
Result :
There are two groups in my instance where type is Group A . So, now only those groups will be visible in Assignment group field
If my answer helped you, please consider marking it as ✅ Correct and giving it a 👍 Helpful — it might help other members in the community too!
Thanks,
Astik T 😊💡
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2025 04:02 AM
Hi @Astik Thombare ,
Excellent ......!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2025 06:33 AM
@Community Alums
you need not use script include for this
You can simply write your script in dictionary override ref qualifier field
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2025 12:13 AM
Hi @Community Alums
I was wondering can't you use sys_user_group_type to store the types and refer that in incident form rather a simple choice? because same types can be used in Groups table. Based on that it will be easy for you to identify the groups and you can stay close to OOTB and can maintain easily. even today the OOTB assignment group have a simple reference condition say type is ITIL, you can use a conditioned reference qualifier based on type selected on incident. I didn't try this out but I feel this is safer option.
If my response solves your query, please marked helpful by selecting Accept as Solution and Helpful
