Grtting error on g_scratchpad using in onsubmit client script(catalog item)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 02:10 AM
Hi team,
i am calling script include in on submit client script and i used the g_scratchpad method i am getting below error
onSubmit script error: ReferenceError: g_scratchpad is not defined:
function () { [native code] }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 02:26 AM - edited 07-23-2024 02:30 AM
Hello @Venky Kshatriy2 ,
Did you declare and assign any value to g_scratchpad variable in any other script like BR or other client script?
You should be declaring and assigning some value to g_scratchpad variable before accessing it.
Please refer below links for more details about g_scratchpad variable-
If my answer solves your issue, please mark it as Accepted✔️ and Helpful👍 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 10:40 AM
Hi @Vrushali Kolte ,
Same script i used in my PDI it's working fine one instance it's working one instance it's not working .I unable to find the error. if know anything help me to resolve this issue

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 02:32 AM
Hi,
You cannot use GlideAjax methods in an onSubmit client script.
GlideAjax runs async, and so the result back from the method is retrieved after the submit has already been processed.
If you need to validate some input on the form using GlideAjax, it must be done with an onChange client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 11:01 AM
Hello,
g_scratchpad object is available only in server-side scripts, and it is used to pass data from the server to the client script. If you need to pass data from the server to the client, you should use a GlideAjax call to fetch the data from the server-side
Create a script include named Decision_table_risk_rating and make sure it's client-callable.
var Decision_table_risk_rating = Class.create();
Decision_table_risk_rating.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getriskratings: function() {
var fromOriginatingCountry = this.getParameter('sysparm_from');
var toDestinationCountry = this.getParameter('sysparam_to');
var mrvs = this.getParameter('sysparam_mrvs');
// Perform your logic here to determine the risk rating
var riskRating = // logic to calculate risk rating;
return riskRating;
}
});
Modify your onSubmit client script to use the GlideAjax call correctly
function onSubmit() {
var partner = g_form.getValue('select_partner');
var segment = g_form.getValue('segment_lead');
var mrvs = g_form.getValue('itinerary');
var vk = new GlideAjax('Decision_table_risk_rating');
vk.addParam('sysparm_name', 'getriskratings');
vk.addParam('sysparm_from', g_form.getValue('from_originating_country'));
vk.addParam('sysparam_to', g_form.getValue('to_destination_country'));
vk.addParam('sysparam_mrvs', mrvs);
vk.getXMLAnswer(function(answer) {
alert('risk_rating: ' + answer);
g_form.setValue('risk_rating', answer);
if (answer == '1' && !partner && !segment) {
g_form.setVisible('partner', true);
g_form.setVisible('segment', true);
g_form.setMandatory('partner', true);
g_form.setMandatory('segment', true);
return false; // Prevent form submission
} else {
return true; // Allow form submission
}
});
return false; // Prevent form submission until GlideAjax call completes
}
Regards,
Chaitanya