- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2022 09:25 AM
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'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2022 11:18 AM
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'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2022 11:18 AM
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'
});