Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Callback function is not working.

Shidhi
Tera Contributor

 

kb_knowledge_base is a reference field. It has a field title, I need to compare that field.
 
I'm getting an undefined error. Below is the code. 
function onLoad() {
    //Type appropriate comment here, and begin script below

    var kbase = g_form.getReference('kb_knowledge_base', getTitle);
    var type = g_form.getValue('u_type');
    var kbase1;

    function getTitle(kbase) {
        kbase1 = kbase.title;

    }

    alert('KBase selected is ' + kbase1);

    if (kbase1 == 'IT' && type == 'standard') {
        g_form.setMandatory('cmdb_ci', false);

    } else
        g_form.setMandatory('cmdb_ci', true);

}

 Any one has any idea why this is not working.

 

Thank you,

shedheesh

1 ACCEPTED SOLUTION

SAI VENKATESH
Kilo Patron
Kilo Patron

Hi @Shidhi 

 

Please try this code:

function onLoad() {
    g_form.getReference('kb_knowledge_base', getTitle);
}

function getTitle(kbase) {
    var kbase1 = kbase.title;
    var type = g_form.getValue('u_type');
    
    alert('KBase selected is ' + kbase1);

    if (kbase1 == 'IT' && type == 'standard') {
        g_form.setMandatory('cmdb_ci', false);
    } else {
        g_form.setMandatory('cmdb_ci', true);
    }
}

 

Thanks and Regards

Sai Venkatesh

View solution in original post

2 REPLIES 2

SAI VENKATESH
Kilo Patron
Kilo Patron

Hi @Shidhi 

 

Please try this code:

function onLoad() {
    g_form.getReference('kb_knowledge_base', getTitle);
}

function getTitle(kbase) {
    var kbase1 = kbase.title;
    var type = g_form.getValue('u_type');
    
    alert('KBase selected is ' + kbase1);

    if (kbase1 == 'IT' && type == 'standard') {
        g_form.setMandatory('cmdb_ci', false);
    } else {
        g_form.setMandatory('cmdb_ci', true);
    }
}

 

Thanks and Regards

Sai Venkatesh

Sandeep Rajput
Tera Patron
Tera Patron

@Shidhi Try the following

 

function onLoad() {
    //Type appropriate comment here, and begin script below

    var kbase = g_form.getReference('kb_knowledge_base', getTitle);
    var type = g_form.getValue('u_type');
    var kbase1;

    function getTitle(kbase) {
        kbase1 = kbase.title;
        alert('KBase selected is ' + kbase1);

        if (kbase1 == 'IT' && type == 'standard') {
            g_form.setMandatory('cmdb_ci', false);

        } else {
            g_form.setMandatory('cmdb_ci', true);
        }

    }
}