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

-O-
Kilo Patron
Kilo Patron

Can you post back the Script as tested by you?

app
Mega Expert

Hello,


It is setting 'ITDS-BI-REQUESTS' for everything.

 

script:

function onSubmit () {

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

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.orderNow(actionname);
}
else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
scratchpad.u_isSupportGroup = true;
g_form.orderNow(actionname);
}

}

}

-O-
Kilo Patron
Kilo Patron

OK, but that is most likely due to some different cause. Can you add extra line

		alert('[' + val + ']\n[' + AppropriateCategory + ']');

after line

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

do a test and let us know what is prompts?

app
Mega Expert

Hello,

This came.


find_real_file.png

-O-
Kilo Patron
Kilo Patron

It seems g_form.getDisplayValue() is another thing that exists only in Portal. You need to switch to values and use

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

Alternatively you could "send in" val (obtained calling getValue) as a GlideAjax parameter, get its display value on server side (in the Script Include) and send it back alongside property1, property2 and property3.