We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Unhandled exception in GlideAjax Cannot read properties of null (reading 'callCity')

Dave_p
Giga Guru

Hi,

I am creating script Include and I am facing this issue. Kindly help.

 

GlideAJAX

 

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

 

Error

 

1.png

 

 

Regards

Suman P.

1 ACCEPTED SOLUTION

JenniferRah
Mega Sage

This line has a period instead of a comma in your client script:

ga.addParam('sysparm_ID', newValue);

 

Beyond that, have you verified these fields have information in them in the record where you are looking them up? I would add some log statements to see how far you are getting and verify the data is getting populated as expected.

View solution in original post

1 REPLY 1

JenniferRah
Mega Sage

This line has a period instead of a comma in your client script:

ga.addParam('sysparm_ID', newValue);

 

Beyond that, have you verified these fields have information in them in the record where you are looking them up? I would add some log statements to see how far you are getting and verify the data is getting populated as expected.