Unhandled exception in GlideAjax

Dave_p
Giga Guru

Hi,

I am working on Script Include and I am getting an error. Kindly help.

 

2.png

 

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

 

3.png

 

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'
});

 

1.png

 

4.png

 

Regards

Suman P.

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@Dave_p 

 

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);
	}
}

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@Dave_p 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Hi @Ankur Bawiskar,

 

I made a mistake in GlideAJAX. It is supposed to be ",". I put ".".

Regards

Suman P.

@Dave_p 

I provided alternate solution as well without scripting

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader