Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 11:55 PM
Hi Team,
below mentioned code i am used to call the script include to on submit client script and setting value based on that restrict the user
front of the service portal it's working fine i am getting value and it's set to variable but
If i used the in catalog item we have a TRYIT UI action if use this button and test click the order button i am getting the bellow error
onSubmit script error: ReferenceError: g_scratchpad is not defined:
function () { [native code] }
function () { [native code] }
function onSubmit() {
if (g_scratchpad.validForm) {
return;
}
var reason1 = g_form.getValue('reason1');
var reason2 = g_form.getValue('reason2');
var mrvs = g_form.getValue('risk_rating_from_country');
var vk = new GlideAjax("Decision_table_risk_rating");
vk.addParam('sysparm_name', 'getriskratings');
vk.addParam('sysparm_from', g_form.getValue('from'));
vk.addParam('sysparam_to', g_form.getValue('to'));
vk.addParam('sysparam_mrvs', mrvs);
vk.getXML(function risk(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('risk rating' + answer);
g_form.setValue('risk_rating', answer);
if (answer == 1 && reason1 == '' && reason2 == '') {
g_form.setVisible('reason1', true);
g_form.setVisible('reason2', true);
g_form.setMandatory('reason1', true);
g_form.setMandatory('reason2', true);
g_scratchpad.validForm = false;
} else {
g_scratchpad.validForm = true;
g_form.submit();
}
});
return false;
}
Front of portal it's setting the variable value in below image
could pls help to resolve this error
Advance thanks.
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 01:11 AM
As far as I know g_scratchpad is not supported in CMS - only in Portal.
A workaround could be "simulating" it, something like:
function onSubmit () {
var scratchpad = getExistingScratchpad() || getCustomScratchpad();
if (scratchpad.validForm) {
return;
}
var reason1 = g_form.getValue('reason1');
var reason2 = g_form.getValue('reason2');
var mrvs = g_form.getValue('risk_rating_from_country');
var vk = new GlideAjax("Decision_table_risk_rating");
vk.addParam('sysparm_name', 'getriskratings');
vk.addParam('sysparm_from', g_form.getValue('from'));
vk.addParam('sysparam_to', g_form.getValue('to'));
vk.addParam('sysparam_mrvs', mrvs);
vk.getXML(function risk (response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('risk rating' + answer);
g_form.setValue('risk_rating', answer);
if (answer == 1 && reason1 == '' && reason2 == '') {
g_form.setVisible('reason1', true);
g_form.setVisible('reason2', true);
g_form.setMandatory('reason1', true);
g_form.setMandatory('reason2', true);
scratchpad.validForm = false;
}
else {
scratchpad.validForm = true;
g_form.submit();
}
});
return false;
function getCustomScratchpad () {
return NOW.g_scratchpad = NOW.g_scratchpad || {};
}
function getExistingScratchpad () {
if (typeof g_scratchpad != 'undefined')
return g_scratchpad;
}
}
11 REPLIES 11
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 05:54 AM
Thanks for explain @-O- it's really helpful to me
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 06:59 AM
You're most welcome 🙂