Javascript error in your browser console : Unhandled exception in GlideAjax in Service Portal

app
Mega Expert

Hello All,

I have written a catalog client script and script include nut getting an error message.

There is a JavaScript error in your browser console

Unhandled exception in GlideAjax in Service Portal

Please let me know how can I solve this.

Client script :

function onSubmit () {

var actionname = g_form.getActionName();
var scratchpad = typeof g_scratchpad == 'undefined' ? NOW : g_scratchpad;

if (scratchpad.isSupportGroup) {
return true;
}

var val = g_form.getValue('datacity_service');

var ga = new GlideAjax('DataCityRequest');

ga.addParam('sysparm_name', 'populateApplicationFields');
ga.getXMLAnswer(populateApplicationFields);

return false;

function populateApplicationFields(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var obj = answer.evalJSON(true);

var PV_Corporate_Request = obj.property1.split(",");
var PV_Customer_Request = obj.property2.split(",");
var PV_Operations_Request = obj.property3.split(",");

var AppropriateCategory = g_form.getValue('appropriate_category');

if ((AppropriateCategory == 'Request Enhancement') || (AppropriateCategory == 'SME-Project Estimates') || (AppropriateCategory == 'Report Defect')) {

if (PV_Corporate_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Corporate-Requests');
scratchpad.isSupportGroup = true;
}
else if (PV_Customer_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Customer-Requests');
scratchpad.isSupportGroup = true;
}
else if (PV_Operations_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Operations-Requests');
scratchpad.isSupportGroup = true;
}
else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
scratchpad.isSupportGroup = true;
}

scratchpad.isSupportGroup = true;
g_form.orderNow(actionname);
}
else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
scratchpad.isSupportGroup = true;
g_form.orderNow(actionname);
}

}

}

 

script include:

var DataCityRequest = Class.create();
DataCityRequest.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
populateApplicationFields: function() {
var obj = {};
obj.property1 = gs.getProperty("Datacity Request - DWBI-Corporate-Requests");
obj.property2 = gs.getProperty("Datacity Request - DWBI-Customer-Requests");
obj.property3 = gs.getProperty("Datacity Request - DWBI-Operations-Requests");

return JSON.stringify(obj);
},
type: 'DataCityRequest'
});

 

Thanks

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

Yeah, me silly, the reference to the function(s) need to be "bound" as below:

	var submitMethod = typeof g_form.orderNow == 'function' ? g_form.orderNow.bind(g_form) : g_form.submit.bind(g_form);

View solution in original post

19 REPLIES 19

-O-
Kilo Patron
Kilo Patron

Yeah, me silly, the reference to the function(s) need to be "bound" as below:

	var submitMethod = typeof g_form.orderNow == 'function' ? g_form.orderNow.bind(g_form) : g_form.submit.bind(g_form);

-O-
Kilo Patron
Kilo Patron

Well, testing in San Diego leads nowhere when using the function reference variable in CMS. For some reason it expects two pushes of the Order Now button.

So I guess the best option is to just have two onSubmit Catalog Client Scripts, one for each platform.

The one for CMS would be:

function onSubmit () {
	var actionname = g_form.getActionName();

	if (NOW.isSupportGroup) {
		return true;
	}

	var val = g_form.getValue('datacity_service');

	var ga = new GlideAjax('DataCityRequest');

	ga.addParam('sysparm_name', 'populateApplicationFields');
	ga.getXMLAnswer(populateApplicationFields);

	return false;

	function populateApplicationFields (response) {
		var obj = JSON.parse(response);

		var PV_Corporate_Request = obj.property1.split(",");
		var PV_Customer_Request = obj.property2.split(",");
		var PV_Operations_Request = obj.property3.split(",");

		var AppropriateCategory = g_form.getValue('appropriate_category');

		if ((AppropriateCategory == 'Request Enhancement') || (AppropriateCategory == 'SME-Project Estimates') || (AppropriateCategory == 'Report Defect')) {
			if (PV_Corporate_Request.indexOf(val) > -1) {
				g_form.setValue('support_group', 'DWBI-Corporate-Requests');
				NOW.isSupportGroup = true;
			}
			else if (PV_Customer_Request.indexOf(val) > -1) {
				g_form.setValue('support_group', 'DWBI-Customer-Requests');
				NOW.isSupportGroup = true;
			}
			else if (PV_Operations_Request.indexOf(val) > -1) {
				g_form.setValue('support_group', 'DWBI-Operations-Requests');
				NOW.isSupportGroup = true;
			}
			else {
				g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
				NOW.isSupportGroup = true;
			}

			NOW.isSupportGroup = true;
			g_form.orderNow(actionname);
		}
		else {
			g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
			NOW.isSupportGroup = true;
			g_form.orderNow(actionname);
		}
	}
}

The one for Portal would be:

function onSubmit () {
	var actionname = g_form.getActionName();

	if (g_scratchpad.isSupportGroup) {
		return true;
	}

	var val = g_form.getValue('datacity_service');

	var ga = new GlideAjax('DataCityRequest');

	ga.addParam('sysparm_name', 'populateApplicationFields');
	ga.getXMLAnswer(populateApplicationFields);

	return false;

	function populateApplicationFields (response) {
		var obj = JSON.parse(response);

		var PV_Corporate_Request = obj.property1.split(",");
		var PV_Customer_Request = obj.property2.split(",");
		var PV_Operations_Request = obj.property3.split(",");

		var AppropriateCategory = g_form.getValue('appropriate_category');

		if ((AppropriateCategory == 'Request Enhancement') || (AppropriateCategory == 'SME-Project Estimates') || (AppropriateCategory == 'Report Defect')) {
			if (PV_Corporate_Request.indexOf(val) > -1) {
				g_form.setValue('support_group', 'DWBI-Corporate-Requests');
				g_scratchpad.isSupportGroup = true;
			}
			else if (PV_Customer_Request.indexOf(val) > -1) {
				g_form.setValue('support_group', 'DWBI-Customer-Requests');
				g_scratchpad.isSupportGroup = true;
			}
			else if (PV_Operations_Request.indexOf(val) > -1) {
				g_form.setValue('support_group', 'DWBI-Operations-Requests');
				g_scratchpad.isSupportGroup = true;
			}
			else {
				g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
				g_scratchpad.isSupportGroup = true;
			}

			g_scratchpad.isSupportGroup = true;
			g_form.submit(actionname);
		}
		else {
			g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
			g_scratchpad.isSupportGroup = true;
			g_form.submit(actionname);
		}
	}
}

app
Mega Expert

Thanks Janos,

This worked

-O-
Kilo Patron
Kilo Patron

You're welcome 🙂

_ChrisHelming
Tera Guru

Right click > Inspect and look at what the error is. It's telling there's an error in your console so go get what the error is and report back.