g_scratchpad.isFormValid? How does it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2020 02:32 AM
I was just looking around to find a solution for making onSubmit client validation work for Service Portal, and found the below solution, which worked perfectly.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0783579
_________________________________________________________________________
function onSubmit() {
if (g_scratchpad.isFormValid){
return true;
}
var actionName = g_form.getActionName();
var ga = new GlideAjax("SOMEFUNCTION");
ga.addParam(.....);
ga.getXML(function() {
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
});
return false;
}
_______________________________________________________________________
But my question is how does g_scratchpad.isFormValid() work? I cannot find g_scratchpad.isFormValid in any of display business rules. Does anyone have idea about this?
- Labels:
-
Multiple Versions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2020 04:56 AM
Hi there,
g_scratchpad.isFormValid is being set and used in the Client Script you shared.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2020 05:13 AM
It is a pity, that the linked KB article does not explain the code, because I think it is a really interesting solution.
When entering the function onSubmit two things happen:
- A asynchronous Ajax request for validating the form values is invoked via ga.getXML().
- The function is exited with a return value of "false", which means that the form will not be submitted for the time being.
The interesting solution is the callback function at ga.getXML() which is invoked after the response for the asynchronous Ajax request comes back.
In that case a new variable isFormvalid is set at the g_scratchpad object. The reason for using the g_scratchpad object is, that you normally have no access to browser objects like window or document. The g_scratchpad object acts here as a data container for passing a value to the onSubmit function.
If you want to know more about the g_scratchpad object, do an internet search for it. There is tons of material on this.
To learn more about xyz you can visit the following chapter in the scripting course in the developer portal: https://developer.servicenow.com/dev.do#!/learn/learning-plans/paris/new_to_servicenow/app_store_lea...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2020 01:08 AM
Is there any news here?
If I could help you, please mark my answer as correct or helpful.
If not, please let me know what you are still missing.
Thanks
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2020 06:17 AM
Like Maik Skoddow mention in his answer
isFormValid is just a variable created by YOUR script.
script will work the same way even if your rename all isFormValid usage to blahblah1.
how does g_scratchpad.isFormValid() work?
It very simple - you just define a brand new object property, manipulate it, that change its value.
During first call of first "if" property is not define result will be false.
No magic here code just does what you asked it to do.
Here is the code that will give similar effect:
function onSubmit() {
if (g_scratchpad.aNewProperty){
return true;
}
setTimeout(function() {
g_scratchpad.aNewProperty = true
}, 3000)
return false;
}