- 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-19-2022 12:45 AM
Hi,
are you sure there is field u_building on alm_asset?
Are you sure the field types are same i.e. u_building and building; both location fileds
If field types are same then it should work fine
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader