g_scratchpad not defined : error coming onSubmit catalog client script

app
Mega Expert

Hello All,

I have written one catalog client script using g_scratchpad.

It is working on portal but on the backend side form.

Please let me know how can this be solved.

Script:

function onSubmit() {

var actionname = g_form.getActionName();
if (g_scratchpad.isSupportGroup) {
return true;
}
var val = g_form.getDisplayValue('datacity_service');

var ga = new GlideAjax("DataCityRequest");
ga.addParam("sysparm_name", "populateApplicationFields");
ga.getXML(populateApplicationFields);

return false;

function populateApplicationFields(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);

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);
}

}

}

 

script Include:

var DataCityRequest = Class.create();
DataCityRequest.prototype = Object.extendsObject(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

Actually, to make it as "safe" as possible, you may want to try a different approach: use g_scratchpad where available, else use NOW:

function onSubmit () {

	var actionname = g_form.getActionName();
	var scratchpad = g_scratchpad || NOW;

	if (scratchpad.u_isSupportGroup) {
		return true;
	}

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

	var ga = new GlideAjax("DataCityRequest");

	ga.addParam("sysparm_name", "populateApplicationFields");
	ga.getXML(populateApplicationFields);

	return false;

	function populateApplicationFields (response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		var obj = JSON.parse(answer);

		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.u_isSupportGroup = true;
			}
			else if (PV_Customer_Request.indexOf(val) > -1) {
				g_form.setValue('support_group', 'DWBI-Customer-Requests');
				scratchpad.u_isSupportGroup = true;
			}
			else if (PV_Operations_Request.indexOf(val) > -1) {
				g_form.setValue('support_group', 'DWBI-Operations-Requests');
				scratchpad.u_isSupportGroup = true;
			}
			else {
				g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
				scratchpad.u_isSupportGroup = true;
			}

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

	}

}

View solution in original post

22 REPLIES 22

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

where are you defining the g_scratchpad.isSupportGroup?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hello Ankur,


this is working in portal.

Like this

function onSubmit() {
g_scratchpad.isSupportGroup;
var actionname = g_form.getActionName();
if (g_scratchpad.isSupportGroup) {
return true;
}

 

thanks

-O-
Kilo Patron
Kilo Patron

g_scratchpad is not defined in CSM. It used to not be defined in Portal either. I see in the meantime they added it to Portal, but not to the legacy/defunct CSM.

Try using global object NOW, that is still (as of San Diego) available in both CSM and Portal.

app
Mega Expert

Hello Janos,

Could you please share the script to use global object NOW.

Thanks