- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 07:04 PM
I have the following Ajax Scripts (Include and Client) in a scope application. For some reason I am getting a browser error: There is a JavaScript error in your browser console. Can you please advise me how to addressed this problem. I am in a lost and not sure how to proceed forward. Help appreciated.
Catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue === 'true') {
alert('onChangeTelecommuter_telecommuter =true= ' + newValue);
g_form.clearValue('building');
g_form.clearValue('column');
g_form.clearValue('floor');
g_form.clearValue('room_cube');
} else {
alert('onChangeTelecommuter_telecommuter =False= ' + newValue);
var sys_id_asset = g_form.getValue('asset');
var ga = new GlideAjax('x_g_lme_ham_classi.getStandardFields'); //this is the script include
ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
ga.addParam("sysparm_asset", sys_id_asset);
ga.getXML(getResponse);
}
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split('|');
g_form.setValue('location', values[0]);
g_form.setValue('building', values[1]);
g_form.setValue('floor', values[2]);
g_form.setValue('column', values[3]);
g_form.setValue('room_cube', values[4]);
}
Script Include:
var getStandardFields = Class.create();
getStandardFields.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFields : function() {
var assetID = this.getParameter('sysparm_asset');
var standardFields = new GlideRecord('alm_asset');
standardFields.addQuery('sys_id',assetID);
standardFields.query();
if(standardFields.next()) {
return standardFields.location.getDisplayValue()+ '|' +
standardFields.u_building.getDisplayValue()+'|' +
standardFields.u_floor.getDisplayValue()+ '|'+
standardFields.u_column.getDisplayValue()+ '|'+
standardFields.u_room_cube.getDisplayValue();
}
return '';
},
type: 'getStandardFields'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 07:31 AM
Hi
try to use getXMLAnswer() in client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue === 'true') {
alert('onChangeTelecommuter_telecommuter =true= ' + newValue);
g_form.clearValue('building');
g_form.clearValue('column');
g_form.clearValue('floor');
g_form.clearValue('room_cube');
} else {
alert('onChangeTelecommuter_telecommuter =False= ' + newValue);
var sys_id_asset = g_form.getValue('asset');
var ga = new GlideAjax('x_g_lme_ham_classi.getStandardFields'); //this is the script include
ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
ga.addParam("sysparm_asset", sys_id_asset);
ga.getXMLAnswer(getResponse);
}
}
function getResponse(response) {
var values = response.toString().split('|');
g_form.setValue('location', values[0]);
g_form.setValue('building', values[1]);
g_form.setValue('floor', values[2]);
g_form.setValue('column', values[3]);
g_form.setValue('room_cube', values[4]);
}
Update script include as this since you are in scope application
var getStandardFields = Class.create();
getStandardFields.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getFields : function() {
var assetID = this.getParameter('sysparm_asset');
var standardFields = new GlideRecord('alm_asset');
standardFields.addQuery('sys_id',assetID);
standardFields.query();
if(standardFields.next()) {
return standardFields.location.getDisplayValue()+ '|' +
standardFields.u_building.getDisplayValue()+'|' +
standardFields.u_floor.getDisplayValue()+ '|'+
standardFields.u_column.getDisplayValue()+ '|'+
standardFields.u_room_cube.getDisplayValue();
}
return '';
},
type: 'getStandardFields'
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 07:19 PM
Can you confirm if your script include has "Accessible from" field set as "All application scopes"?
Are you getting the alert that you have in your client script?
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 05:33 AM
Yes, the "All application scopes" is set up. The message is in the browser.
Kumar, If look at the inspect in the browser if have the following message. Kumar thank you for collaboration and education is appreciated. Need anything else please let me know.
Also I am getting the message below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 07:31 AM
Hi
try to use getXMLAnswer() in client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue === 'true') {
alert('onChangeTelecommuter_telecommuter =true= ' + newValue);
g_form.clearValue('building');
g_form.clearValue('column');
g_form.clearValue('floor');
g_form.clearValue('room_cube');
} else {
alert('onChangeTelecommuter_telecommuter =False= ' + newValue);
var sys_id_asset = g_form.getValue('asset');
var ga = new GlideAjax('x_g_lme_ham_classi.getStandardFields'); //this is the script include
ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
ga.addParam("sysparm_asset", sys_id_asset);
ga.getXMLAnswer(getResponse);
}
}
function getResponse(response) {
var values = response.toString().split('|');
g_form.setValue('location', values[0]);
g_form.setValue('building', values[1]);
g_form.setValue('floor', values[2]);
g_form.setValue('column', values[3]);
g_form.setValue('room_cube', values[4]);
}
Update script include as this since you are in scope application
var getStandardFields = Class.create();
getStandardFields.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getFields : function() {
var assetID = this.getParameter('sysparm_asset');
var standardFields = new GlideRecord('alm_asset');
standardFields.addQuery('sys_id',assetID);
standardFields.query();
if(standardFields.next()) {
return standardFields.location.getDisplayValue()+ '|' +
standardFields.u_building.getDisplayValue()+'|' +
standardFields.u_floor.getDisplayValue()+ '|'+
standardFields.u_column.getDisplayValue()+ '|'+
standardFields.u_room_cube.getDisplayValue();
}
return '';
},
type: 'getStandardFields'
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2022 08:52 AM
Ankur, yes the script is fixed. Now the only confusing aspect is that building and location are not displaying. I wonder if it is because they are reference fields and I am not pulling the right value. The floor, column and room_cube are displayed correctly. Any thoughts regarding the building and location!!!!