The CreatorCon Call for Content is officially open! Get started here.

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

huyjor
Tera Contributor

How about this?

 

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

    if (g_form.getValue('state') == 'On Hold') {
        g_form.addOption('hold_reason', 'dnt', 'Do Not Touch',3);
    } else {
        g_form.removeOption('hold_reason', 'dnt');
    }

    //Type appropriate comment here, and begin script below

}

Sandeep Rajput
Tera Patron
Tera Patron

@huyjor Subcategory field is dependent field on the category field on the incident form. Which means the options shown on subcategory field is directly dependent on the category field.

 

Hence this option can't be controlled via a client script. The choice ServiceNow needs to be added in the choice list of subcategory field with a dependent category software.

Screenshot 2023-12-20 at 11.20.27 PM.pngScreenshot 2023-12-20 at 11.21.03 PM.png

ok, i see. Thanks 

@huyjor Please mark the response helpful and correct if it addressed your question