- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 01:09 AM
Hi,
I am working on Script Include and I am getting an error. Kindly help.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('locationDetailsClass');
ga.addParam('sysparm_name', 'locationDetailsFunction');
ga.addParam('sysparm_ID'. newValue);
ga.getXML(callBackFunction);
function callBackFunction(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
var op = JSON.parse(answer);
g_form.setValue('project_city', op.callCity);
g_form.setValue('project_street', op.callStreet);
g_form.setValue('project_state_province', op.callState);
g_form.setValue('project_zip_postal_code', op.callZip);
g_form.setValue('cost_center', op.costCenter);
}
}
Script Include
var locationDetailsClass = Class.create();
locationDetailsClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {
locationDetailsFunction: function(){
var keyFunction = this.getParameter('sysparm_ID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', keyFunction);
gr.query();
if(gr.next()){
var jsonObj = {};
jsonObj.callCity = gr.getValue('city');
jsonObj.callStreet = gr.getValue('street');
jsonObj.callState = gr.getValue('state');
jsonObj.callZip = gr.getValue('zip');
jsonObj.costCenter = gr.getDisplayValue('cost_center');
return JSON.stringify(jsonObj);
}
},
type: 'locationDetailsClass'
});
Regards
Suman P.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2025 04:48 AM
I found an issue with the following line in your client script.
ga.addParam('sysparm_ID'. newValue);
Here instead of using a comma (,) you used a dot(.), the line should be as follows.
ga.addParam('sysparm_ID', newValue);
Here is the updated client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('locationDetailsClass');
ga.addParam('sysparm_name', 'locationDetailsFunction');
ga.addParam('sysparm_ID', newValue);
ga.getXML(callBackFunction);
function callBackFunction(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
var op = JSON.parse(answer);
g_form.setValue('project_city', op.callCity);
g_form.setValue('project_street', op.callStreet);
g_form.setValue('project_state_province', op.callState);
g_form.setValue('project_zip_postal_code', op.callZip);
g_form.setValue('cost_center', op.costCenter);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2025 06:14 AM
try this
Client Script: You need to use getXMLAnswer() and also clear the values if the value is cleared
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('project_city');
g_form.clearValue('project_street');
g_form.clearValue('project_state_province');
g_form.clearValue('project_zip_postal_code');
g_form.clearValue('cost_center');
}
if (oldValue != newValue) {
var ga = new GlideAjax('locationDetailsClass');
ga.addParam('sysparm_name', 'locationDetailsFunction');
ga.addParam('sysparm_ID', newValue);
ga.getXMLAnswer(function(answer) {
var op = JSON.parse(answer);
g_form.setValue('project_city', op.callCity);
g_form.setValue('project_street', op.callStreet);
g_form.setValue('project_state_province', op.callState);
g_form.setValue('project_zip_postal_code', op.callZip);
g_form.setValue('cost_center', op.costCenter);
});
}
}
Since this is for catalog variable you can handle this without scripting
check this link which is a new feature added in Utah
Auto-populate a variable based on a reference type variable (Utah)
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2025 04:48 AM
I found an issue with the following line in your client script.
ga.addParam('sysparm_ID'. newValue);
Here instead of using a comma (,) you used a dot(.), the line should be as follows.
ga.addParam('sysparm_ID', newValue);
Here is the updated client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('locationDetailsClass');
ga.addParam('sysparm_name', 'locationDetailsFunction');
ga.addParam('sysparm_ID', newValue);
ga.getXML(callBackFunction);
function callBackFunction(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
var op = JSON.parse(answer);
g_form.setValue('project_city', op.callCity);
g_form.setValue('project_street', op.callStreet);
g_form.setValue('project_state_province', op.callState);
g_form.setValue('project_zip_postal_code', op.callZip);
g_form.setValue('cost_center', op.costCenter);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2025 06:14 AM
try this
Client Script: You need to use getXMLAnswer() and also clear the values if the value is cleared
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('project_city');
g_form.clearValue('project_street');
g_form.clearValue('project_state_province');
g_form.clearValue('project_zip_postal_code');
g_form.clearValue('cost_center');
}
if (oldValue != newValue) {
var ga = new GlideAjax('locationDetailsClass');
ga.addParam('sysparm_name', 'locationDetailsFunction');
ga.addParam('sysparm_ID', newValue);
ga.getXMLAnswer(function(answer) {
var op = JSON.parse(answer);
g_form.setValue('project_city', op.callCity);
g_form.setValue('project_street', op.callStreet);
g_form.setValue('project_state_province', op.callState);
g_form.setValue('project_zip_postal_code', op.callZip);
g_form.setValue('cost_center', op.costCenter);
});
}
}
Since this is for catalog variable you can handle this without scripting
check this link which is a new feature added in Utah
Auto-populate a variable based on a reference type variable (Utah)
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2025 08:55 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2025 11:56 PM
As per new community feature you can mark multiple responses as correct.
Thank you for marking my response as helpful.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader