Ankur Bawiskar
Tera Patron

@Stergios Stergi 

try this

function onSubmit() {
    // Get the selected assignment group
    var group = g_form.getValue('assignment_group');

    // Core & Core Peripherals sys_id
    var CORE_GROUP = '302f396287ff22506682653e8bbb3542';

    // Only enforce the rule if:
    // 1. We are assigning to the Core group, AND
    // 2. The core_sub_category field exists on the form
    if (group === CORE_GROUP) {
        // Check if the field exists on the form
        var fieldControl = g_form.getControl('core_sub_category');

        // If field exists on the form, then validate it
        if (fieldControl) {
            var coreSub = g_form.getValue('core_sub_category');

            // If no subcategory is selected, show error and block submit
            if (!coreSub) {
                g_form.showFieldMsg(
                    'core_sub_category',
                    'You must select a Core Sub Category before assigning this group.',
                    'error'
                );
                return false; // Prevents the form from submitting
            }
        }
        // If field does not exist on the form, do nothing (allow submit)
    }

    return true; // Allow submit in all other cases
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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