- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 07:05 AM
HI All,
I was written below onsubmit client script and used g_scratchpad. the code working in portal View and not in Native UI and getting below Error.
"onSubmit script error: ReferenceError: g_scratchpad is not defined:
function () { [native code] }"
Requirement: While submit the form we need to check the service is AMS related or not. if AMS service we need to prevent the form, if not AMS service we need allow to submit the form.
And populating URL in Onchange client script.
My script:
function onSubmit() {
if (g_scratchpad.isFormValid)
return true;
//var amsproceed = true;
var user = g_form.getValue('services');
var ga = new GlideAjax('AMScatalogitem'); //Name of the Script Include
ga.addParam('sysparm_name', 'GetAMSservices'); //name of function in script include
ga.addParam('sysparm_user', user);
ga.getXMLAnswer(getData);
return false;
function getData(answer) {
if (answer == "true") {
g_form.addErrorMessage('This serivce maintained by AMS team. Please use below URL link to submit the form');
return false;
}
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
If anyone one help its really helpful.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 07:49 AM
To Allen's point, g_scratchpad is something that is initiated server side to make additional data available to the client, almost exclusively established via business rule. You wouldn't be able to establish and utilize g_scratchpad from the client side.
How are you attempting to populate g_scratchpad.isFormValid? Also, I would consider that onSubmit AJAX calls can sometimes run into issues, unless waiting for the XML return. From an end user experience perspective, the wait to see if the form submits can be a negative one, and then if I've filled out an entire form just to be told that it's the wrong form is extremely frustrating. I might suggest trying to do that validation and establish whether it's the right form at the very beginning, and using those variables in advance of submit to figure out if they need to be going elsewhere. This way, you are ensuring the best end user experience.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 07:29 AM
Hello,
From my understanding, display business rules don't work on catalog items, period.
Are you sure it's actually working on service portal? Have you check that and verified?
You're returning true, but if the scratchpad returns undefined, null, etc. then it's still going to return true because it's set to execute anyway and process unless it's hit with a return false.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 09:40 PM
This is not business rule. This is catalog client script using script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2022 07:49 AM
To Allen's point, g_scratchpad is something that is initiated server side to make additional data available to the client, almost exclusively established via business rule. You wouldn't be able to establish and utilize g_scratchpad from the client side.
How are you attempting to populate g_scratchpad.isFormValid? Also, I would consider that onSubmit AJAX calls can sometimes run into issues, unless waiting for the XML return. From an end user experience perspective, the wait to see if the form submits can be a negative one, and then if I've filled out an entire form just to be told that it's the wrong form is extremely frustrating. I might suggest trying to do that validation and establish whether it's the right form at the very beginning, and using those variables in advance of submit to figure out if they need to be going elsewhere. This way, you are ensuring the best end user experience.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2022 01:58 AM
I wrote below script to modified but not prevent the form.
function onSubmit() {
var user = g_form.getValue('services');
var ga = new GlideAjax('AMScatalogitem'); //Name of the Script Include
ga.addParam('sysparm_name', 'GetAMSservices'); //name of function in script include
ga.addParam('sysparm_user', user);
ga.getXML(getData);
function getData(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if (answer == 'true' || answer == true) {
g_form.addErrorMessage('This serivce maintained by AMS team. Please use below URL link to submit the form');
return false;
}
}
}