glideAJAX scriptInclude question

Community Alums
Not applicable

Hi,

 

I have created a glideAJAX and scriptInclude script to autopopulate the values. I am getting an error saying TypeError: addParam is not a function. Kindly help.

 

GlideAJAX

 

g.png

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

	var ga = new GlideAjax('officerNameClass');
	ga.addparam('sysparm_name', 'officerNameFunction');
	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('user_id_officer', op.userid);
		g_form.setValue('office_phone_officer', op.officePhone);
		g_form.setValue('cost_center_officer', op.costCenter);
	}


}

 

ScriptInclude

 

s.png

 

var officerNameClass = Class.create();
officerNameClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    officerNameFunction: function() {
 var officeKey = this.getParameter('sysparm_id');
 var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', officeKey);
gr.query();
if(gr.next()){
	var jsonObj = {};
	jsonObj.userid = gr.getValue('user_name').toString();
	jsonObj.officePhone = gr.getValue('phone').toString();
	jsonObj.costCenter = gr.getdisplayValue('cost_center').toString();
	var json = JSON().encode(jsonObj);
}

},

    type: 'officerNameClass'
});

 

1.png

 

Regards

Suman P.

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Anand Kumar P
Giga Patron
Giga Patron

HI @Community Alums ,

Param not param "P" is capital


	var ga = new GlideAjax('officerNameClass');
	ga.addParam('sysparm_name', 'officerNameFunction');
	ga.addParam('sysparm_id', newValue);


Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
 

View solution in original post

2 REPLIES 2

Anand Kumar P
Giga Patron
Giga Patron

HI @Community Alums ,

Param not param "P" is capital


	var ga = new GlideAjax('officerNameClass');
	ga.addParam('sysparm_name', 'officerNameFunction');
	ga.addParam('sysparm_id', newValue);


Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
 

Abhishek_Thakur
Mega Sage

Hello @Community Alums ,

You can follow the below script include and client script code.

 

Script Include: -

 

var officerNameClass = Class.create();
officerNameClass.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    officerNameFunction: function() {
 var officeKey = this.getParameter('sysparm_id');
 var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', officeKey);
gr.query();
if(gr.next()){
	var jsonObj = {};
	jsonObj.userid = gr.getValue('user_name').toString();
	jsonObj.officePhone = gr.getValue('phone').toString();
	jsonObj.costCenter = gr.getdisplayValue('cost_center').toString();
	var json = JSON().encode(jsonObj);
return json;
}

},

    type: 'officerNameClass'
});

 

 

Client script:-

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

	var ga = new GlideAjax('officerNameClass');
	ga.addParam('sysparm_name', 'officerNameFunction');
	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('user_id_officer', op.userid);
		g_form.setValue('office_phone_officer', op.officePhone);
		g_form.setValue('cost_center_officer', op.costCenter);
	}


}

 

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

 

Regards,

Abhishek Thakur