why I can't get parameters from client script in the ajax class method

zhanglixin
Tera Expert

Client Script onload method

zhanglixin_0-1713681194815.png

Ajax class method  (of course I have extended global.AbstractAjaxProcessor)

zhanglixin_1-1713681290657.png

 

1 ACCEPTED SOLUTION

DYCM
Mega Sage

Hi @zhanglixin ,

Please pass strings as the parameters to the Ajax class, update your code as shown below:

 

function onLoad() {
	var inRecordLog = {};
	inRecordLog.screen_name_report_name = "Screen Name Report Name";
	inRecordLog.manipulate_content = "loading";

	var gAjax = new GlideAjax("ajaxUtil");
	gAjax.addParam("sysparm_name","recordLogClient");
	gAjax.addParam("sysparm_inRecordLog", JSON.stringify(inRecordLog));
	gAjax.addParam("sysparm_inOnclickFlag", "false");
	gAjax.getXMLAnswer(function(response){

	});
   
}

 

Please check this article for explanation: https://www.servicenow.com/community/developer-forum/how-do-i-pass-an-array-to-glideajax/m-p/2141792

 

In your Ajax class, use JSON.parse to convert string to JSON object after you get the value of the parameter.

View solution in original post

2 REPLIES 2

James Chun
Kilo Patron

Hi @zhanglixin,

 

Do you get anything from the log?

Or are the parameters the only bits that are missing from the log?

 

Cheers

DYCM
Mega Sage

Hi @zhanglixin ,

Please pass strings as the parameters to the Ajax class, update your code as shown below:

 

function onLoad() {
	var inRecordLog = {};
	inRecordLog.screen_name_report_name = "Screen Name Report Name";
	inRecordLog.manipulate_content = "loading";

	var gAjax = new GlideAjax("ajaxUtil");
	gAjax.addParam("sysparm_name","recordLogClient");
	gAjax.addParam("sysparm_inRecordLog", JSON.stringify(inRecordLog));
	gAjax.addParam("sysparm_inOnclickFlag", "false");
	gAjax.getXMLAnswer(function(response){

	});
   
}

 

Please check this article for explanation: https://www.servicenow.com/community/developer-forum/how-do-i-pass-an-array-to-glideajax/m-p/2141792

 

In your Ajax class, use JSON.parse to convert string to JSON object after you get the value of the parameter.