Unhandled Exception in Glide Ajax - Script Include

neil_b
Tera Guru

I have a record producer with a list collector variable, and I am trying to accomplish adding a check box so that if the user checks the box, the list collector variable will select all items in the list.


When I try to test the functionality, I get this JavaScript/GlideAjax error.

Javascript Error.png

Script Include:

 

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

	getRecords: function() {

		var fieldName = this.getParameter('user_list'); // i entered the unique variable name
		var catItem = this.getParameter('cat_item_sys_id'); // i entered the sys_id of the RP

		var variableGR = new GlideRecord('item_option_new');
		variableGR.addQuery('name', fieldName);
		variableGR.addQuery('cat_item', catItem);
		variableGR.setLimit(1);
		variableGR.query();
		if (variableGR.next()) {
						
			var tableLookupGR = new GlideRecord(variableGR.getValue('list_table'));

			var encodedQuery = variableGR.getValue('reference_qual');
			tableLookupGR.addEncodedQuery(encodedQuery);

			var returnValues = [];
			tableLookupGR.query();
			while (tableLookupGR.next()) {
				returnValues.push({
					"value": tableLookupGR.getUniqueValue(),
					"displayValue": tableLookupGR.getDisplayValue()
				});
			}
			return JSON.stringify(returnValues);
		}

	},

	type: 'MyCatalogUtils'
});

 

 

Catalog Client Script

 

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


	var listCollectorName = "user_list";

	if(g_list != "undefined"){
		var listCollector = g_list.get(listCollectorName);
		if(!listCollector)return;
	}

	if(newValue == 'false'){
		g_form.setValue(listCollectorName , '');
		return;
	}

	var ga = new GlideAjax('MyCatalogUtils');
	ga.addParam('sysparm_name' , 'getRecords');
	ga.addParam('sysparm_field_name' , listCollectorName);
	ga.addParam('sysparm_cat_item' , g_form.getUniqueValue());
	ga.getXMLAnswer(function(response){

		if(response == null)return;
		response = JSON.parse(response);

		if(listCollector){
			response.forEach(function(el){
				listCollector.addItem(el.value , el.displayValue);
			});
		} else {
			var values = response.map(function(val){ return val.value;});
			var display = response.map(function(val){return val.displayValue;});
			g_form.setValue(listCollectorName , values.join(",") , display.join(", "));
		}
	});

}

 

 

Here are some screen captures.

Client Script Form.png

The idea from this derived from this post: How To - Select all records for a list collector - ServiceNow Community

1 ACCEPTED SOLUTION

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

I just had a quick look but it seems to me be your parameter names in the client script and script include do not match, i.e.:

Client script:

ga.addParam('sysparm_field_name' , listCollectorName);
ga.addParam('sysparm_cat_item' , g_form.getUniqueValue());

While the Script Include is looking for different parameters:

var fieldName = this.getParameter('user_list'); // i entered the unique variable name
var catItem = this.getParameter('cat_item_sys_id'); // i entered the sys_id of the RP

View solution in original post

3 REPLIES 3

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

I just had a quick look but it seems to me be your parameter names in the client script and script include do not match, i.e.:

Client script:

ga.addParam('sysparm_field_name' , listCollectorName);
ga.addParam('sysparm_cat_item' , g_form.getUniqueValue());

While the Script Include is looking for different parameters:

var fieldName = this.getParameter('user_list'); // i entered the unique variable name
var catItem = this.getParameter('cat_item_sys_id'); // i entered the sys_id of the RP

Hi Laszlo, thank you for responding. 

 

I tried to change the parameters on the Script Include to mirror the Client Script so now it shows

        var fieldName = this.getParameter('sysparm_field_name');
        var catItem = this.getParameter('sysparm_cat_item');
 

The error no longer appears. Thank you Laszlo!

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

Neil, you would not need the 'sysparm_' part in the script include btw, so

var fieldName = this.getParameter('field_name');
var catItem = this.getParameter('cat_item');

should do the trick.