Unhandled exception in GlideAjax

jyan3
Kilo Guru

Hi I'm trying to call a script Include from a Catalog Client Script and I get the unhelpful message of "Unhandled exception in GlideAjax"

The script is supposed to parse a list of cmdb_ci_bussiness_app sys_id and check to see if the install type is "emulate" then set a field to mandatory. Not sure what I'm doing wrong with the ajax to look up the install_type column

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('CheckInstallType');
var setMandatory = false;
var options = ((newValue).toString()).split(','); //turns your list collector output into an array you can iterate through
{
for (i = 0; i < options.length; i++) {
ajax.addParam('sysparm_name', 'getBusinessApp');
ajax.addParam('sysparm_app', options[i]);
var result = ajax.getXML(setMandatory);
if (result == 'emulate') {
setMandatory = true;
}
}
}
g_form.setMandatory('user_to_emulate', setMandatory);

}

function setMandatory(response) {
//alert("SK:inside");
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);

return obj.InstallType == 'emulate';

}

 

 

 

Script Include:

var CheckInstallType = Class.create();
CheckInstallType.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getBusinessApp: function() {
var businessApp = {};
var sysapp = this.getParameter('sysparm_app');
var app = new GlideRecord("cmdb_ci_business_app");
app.addQuery("sys_id", sysapp);
app.query();
while (app.next()) {
businessApp.InstallType = app.install_type.getDisplayValue().toString();
}
var json = new JSON();
var data = json.encode(InstallType);
return data;
},
type: 'CheckInstallType'
});

 

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage
Mega Sage

Try once with below scripts.

 

Client Script.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ajax = new GlideAjax('CheckInstallType');
    var options = newValue.toString();
	
    ajax.addParam('sysparm_name', 'getBusinessApp');
    ajax.addParam('sysparm_app', options);
    ajax.getXML(setMandatory);

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

        if (answer =='true') {
            g_form.setMandatory('user_to_emulate', true);
        }
    }

}

 

Script Include

var CheckInstallType = Class.create();
CheckInstallType.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
    getBusinessApp: function() {
        
        var sysapp = this.getParameter('sysparm_app');
        var app = new GlideRecord("cmdb_ci_business_app");

		app.addEncodedQuery("sys_idIN" + sysapp);
        app.query();
		
        while (app.next()) {
			if(app.install_type.toString() == 'emulate'){
				return 'true';
			}
        }

        return 'false';
    },
	
    type: 'CheckInstallType'
});

View solution in original post

1 REPLY 1

Muhammad Khan
Mega Sage
Mega Sage

Try once with below scripts.

 

Client Script.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ajax = new GlideAjax('CheckInstallType');
    var options = newValue.toString();
	
    ajax.addParam('sysparm_name', 'getBusinessApp');
    ajax.addParam('sysparm_app', options);
    ajax.getXML(setMandatory);

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

        if (answer =='true') {
            g_form.setMandatory('user_to_emulate', true);
        }
    }

}

 

Script Include

var CheckInstallType = Class.create();
CheckInstallType.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
    getBusinessApp: function() {
        
        var sysapp = this.getParameter('sysparm_app');
        var app = new GlideRecord("cmdb_ci_business_app");

		app.addEncodedQuery("sys_idIN" + sysapp);
        app.query();
		
        while (app.next()) {
			if(app.install_type.toString() == 'emulate'){
				return 'true';
			}
        }

        return 'false';
    },
	
    type: 'CheckInstallType'
});