Glide AJAX not working

umaaggarwal
Giga Guru
Giga Guru

Hello Experts,

My goal is to have a string field on incident form and when the form loads, it should get populated with CI details ( like name , manufacturer , asset tag etc ) based on what is selected under configuration item.

To achieve this, I created onload client script, and using glideajax to interact with script include which returns the data from that specific configuration item, however I am getting null value as a result. Can someone please help ?

 

Below is the client script 

 

find_real_file.png

script include 

 

find_real_file.png

 

Output 😞

 

find_real_file.png

 

 

17 REPLIES 17

Brent Sutton
Mega Sage

Hi Ya,

Can you please try the following code:

OnChange Client Script (config should look like below)

find_real_file.png

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {} //run onLoad and onChange
	
	g_form.clearMessages(); //clear any previous messages

	if (newValue) {
		var ga = new GlideAjax("getConfigDetails");
		ga.addParam("sysparm_name","getInfo");
		ga.addParam("sysparm_ci_info",newValue); //newValue contains the sys_id of cmdb_ci
		ga.getXMLAnswer(upDateInfo); //return just the answer
	}
	else {
		g_form.setValue("u_ci_config",""); //clear the contents of CI Config if Configuration Item is empty
	}


	function upDateInfo(answer) {
		if (answer) {
			g_form.setValue("u_ci_config",answer); 
			g_form.addInfoMessage("Response function call completed: " + answer);
		}
		else {
			g_form.setValue("u_ci_config",""); //if there is no value in the answer then clear the field
		}
	}
}

 Script Include (Client Callable):

find_real_file.png

var getConfigDetails = Class.create();
getConfigDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getInfo: function() {
		var onFormCi = this.getParameter("sysparm_ci_info");
		
		var ciRec = new GlideRecord("cmdb_ci");
		var result = "";
		if (ciRec.get(onFormCi)) {
			result = gs.getMessage("Name: {0} \nAsset Tag: {1}",[ciRec.name,ciRec.asset_tag]);
		}
		return result;
	},
	

    type: 'getConfigDetails'
});

 

Please also ensure that your String Dictionary entry has a reasonable character length to accept the AJAX answer. I set mine to 1000 so it would accept multi-line input. Should look like the following:

find_real_file.png

I've tested this in my developer instance and it is working correctly. Let me know if it works for you.

Brent

P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.

Hello,

 

Can you please ensure that client callable check box is selected in script include.

I have seen it returning null when that is not enabled.

 

Regards,

Sateesh Kumar Devadoss

not working for me 😞

Hi, Are you using the code and configuration exactly as I provided? Client Script should be onChange type (not onLoad) and script include needs to be client callable. Does the result show in the info message on the client? Double check the field names are correct for your configuration. Like I said, everything is working correctly in my Kingston development instance. If you use the code exactly as specified you should have no issues. Brent

Hi

Did any of the suggestions work for you? If so, please mark as correct and close down this thread.

Thanks,

Brent