Client Script that checks a variable has been field in if users tries to assign it to a group

Stergios Stergi
Giga Guru

Hello guys,

 

I have this client script that checks whether a Variable (LoV) is selected if the user tries to assign the inc to a specific assignment group.

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

    // Required variable
    var coreSub = g_form.getValue('core_sub_category');

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

    // If assigned to Core group AND no subcategory selected
    if (group === CORE_GROUP && !coreSub) {

        g_form.showFieldMsg(
            'core_sub_category',
            'You must select a Core Sub Category before assigning this group.',
            'error'
        );

        return false;  // prevents the catalog item from submitting
    }

    return true;
}
 
 
The issue is, the script prevents assignment even for inc that don't have the Variable (Core Subcategory) present.
 
We have such cases because we had inc submitted BEFORE the introduction of the Core Subcategory Variable.

Is there a way to add a check before the script runs, that will allow the reassignment when the field is not present at all?

Thank you and have a happy holiday!
0 REPLIES 0