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

I don't think it is documented. It is a global object hosting all sort of global client side data, like the current user, its roles, etc. In other words there wouldn't be much to document about it either. Cause it is just an object in the end, having a bunch of properties that contain data for stuff documented indirectly elsewhere - like g_user.hasRole.

harshwatvani
Tera Contributor

Could you please share any documentation for global object NOW?
It would be great if you can provide any article related to that too. Thanks

As already stated, as far as I know, there is not documentation or articles about the object.

I suppose it is meant to be a "safe" place where ServiceNow can store global stuff, data or even functionality, so that it does not conflict with global stuff of the browser.