Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

When assignment group type is Test integration user then category and subcategoryis mandatory

adityaashok
Tera Contributor

 

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!!


 

1 ACCEPTED SOLUTION

Yogesh11bhatt
Tera Expert

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:

JavaScript
 
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:

JavaScript
 
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);
        }
    });
}

 

View solution in original post

8 REPLIES 8

Deepak Shaerma
Mega Sage

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

 

 

Yogesh11bhatt
Tera Expert

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:

JavaScript
 
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:

JavaScript
 
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);
        }
    });
}

 

Hello @Yogesh11bhatt ,

This is working fine.

Thanks for your quick response.

namanajain
Tera Expert

Hi @adityaashok 
This code will work 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    // Fetch Assignment Group reference
    var groupName = g_form.getDisplayValue('assignment_group').trim();
    console.log(groupName );
    console.log(groupName == "CSM Support");
    if (groupName == "CSM Support") {
            g_form.setMandatory('category', true);
            g_form.setMandatory('subcategory', true);
    } else {
            g_form.setMandatory('category', false);
            g_form.setMandatory('subcategory', false);
        }
}
 
I also checked this