Help on g_form.addoption

huyjor
Tera Contributor
Hello
I'm trying to practice g_form.addoption on incident table. When the user select software, it should add the option "serviceNow". Else it should remove the option. I'm getting an error: onChange script error: TypeError: g_form.addoption is not a function function () { [native code] }. Thanks for your help. 
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    if (g_form.getValue('category') == 'software') {
        g_form.addoption('subcategory', 'snow', 'ServiceNow', 3);
    } else {
        g_form.removeOptions('subcategory', 'snow');
    }

    //Type appropriate comment here, and begin script below

}
8 REPLIES 8

Sandeep Rajput
Tera Patron
Tera Patron

@huyjor Please try the following script.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    if (g_form.getValue('category') == 'software') {
        g_form.addOption('subcategory', 'snow', 'ServiceNow', 3);
    } else {
        g_form.removeOption('subcategory', 'snow');
    }

    //Type appropriate comment here, and begin script below

}

The error went away but the option under subcategory is not showing up. 

@huyjor Try this.

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    if (g_form.getValue('category') == 'software') {
        g_form.addOption('subcategory', 'snow', 'ServiceNow');
    } else {
        g_form.removeOption('subcategory', 'snow');
    }

    //Type appropriate comment here, and begin script below

}

 

Still not showing 😥