Catalog client script

Ram012
Tera Contributor

Below the code not working 

 

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

Var ga = new Glideajax('UserDetails');
ga.addparam('sysparm_name', check Employee);
ga.addparam('sysparm_user_sys_id',newValue);
ga.getXML(processtheresult);

function processtheresult(response){
var answer = response.responseXML.documentElement.getAttribute("answer");

if(answer == true){
g_form.setVisible('file_100',true);
}else{
g_form.setVisible('file_100',false);
}

 

Any idea what is the exact error above the code.

1 REPLY 1

HIROSHI SATOH
Mega Sage

There are several issues with the code you provided. Here are the causes of the errors and how to fix them:

  1. Var should be var: In JavaScript, the keyword for declaring variables is var, but your code uses Var with a capital "V". Change it to var.

  2. Typo in addParam: ga.addparam should be ga.addParam with a capital "P".

  3. Missing quotes around check Employee: The string check Employee should be enclosed in quotes like this: ga.addParam('sysparm_name', 'check Employee');.

  4. Function name consistency: The function name processtheresult needs to be consistent. If it's named processTheResult in one place, it should be the same everywhere.

  5. Comparison of answer: The answer variable might be returned as a string, so you should compare it using if(answer == 'true') or explicitly convert it to a Boolean.

(Not tested)Here is the corrected code:

 

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

    var ga = new GlideAjax('UserDetails');
    ga.addParam('sysparm_name', 'check Employee');
    ga.addParam('sysparm_user_sys_id', newValue);
    ga.getXML(processTheResult);

    function processTheResult(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");

        if (answer == 'true') {
            g_form.setVisible('file_100', true);
        } else {
            g_form.setVisible('file_100', false);
        }
    }
}