How to filter Assignment Group based on Group Type choice field on Incident form?

Not applicable

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.

1 ACCEPTED SOLUTION

Astik Thombare
Tera Sage

Hi @Community Alums ,

 

I have created one field on incident table with choices as Group A , Group B etc

AstikThombare_0-1751783853844.png

 

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

 

AstikThombare_1-1751783993972.png

Now , i have given these type to certain groups 

 

AstikThombare_2-1751784064851.png

 

I have created one script include as below 

 

AstikThombare_3-1751784143028.png

 

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 

 

AstikThombare_4-1751784294865.png

 

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 

 

AstikThombare_6-1751784416624.png

AstikThombare_7-1751784451823.png

AstikThombare_8-1751784511562.png

 

 

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 😊💡

 

 

View solution in original post

5 REPLIES 5

Astik Thombare
Tera Sage

Hi @Community Alums ,

 

I have created one field on incident table with choices as Group A , Group B etc

AstikThombare_0-1751783853844.png

 

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

 

AstikThombare_1-1751783993972.png

Now , i have given these type to certain groups 

 

AstikThombare_2-1751784064851.png

 

I have created one script include as below 

 

AstikThombare_3-1751784143028.png

 

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&colon;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 

 

AstikThombare_4-1751784294865.png

 

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 

 

AstikThombare_6-1751784416624.png

AstikThombare_7-1751784451823.png

AstikThombare_8-1751784511562.png

 

 

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 😊💡

 

 

Not applicable

Hi @Astik Thombare ,

Excellent ......! 

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

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

Chai Maddula
Giga Guru

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.

 

ChaiMaddula_0-1751785961551.png

 

 

If my response solves your query, please marked helpful by selecting Accept as Solution and Helpful