- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 11:07 AM
I am trying to set-up a client script that will show an error message on a form if a specific field is not populated. Being a novice at scripting I seem to be having some difficulties and not getting it right. This is what I have for my script:
I have attached a screenshot of the script. Any assistance is appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 11:23 AM - edited 06-16-2023 11:23 AM
The way the script is written now is going to run when the form loads (onLoad script). Are you sure you want it to run this when the form first loads versus when it's submitted?
This will do it if you do want it to run onLoad:
function onLoad() {
//Type appropriate comment here, and begin script below
var taxonomy = g_form.getValue('spm_taxonomy_node');
if(!taxonomy) {
g_form.addErrorMessage('Service cannot move beyond pipeline phase and approved status until a taxonomy node is set.');
}
}
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 11:31 AM
This is a new client script that I created, and I don't have much coding experience,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 11:41 AM
That you don't have much coding experience, is not important here. What is important, what the actual functional requirement is.
That's why I'm asking, though unfortunately you are not answering on this. Else we could have helped you on that also.
Kind regards,
Mark
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
06-16-2023 02:10 PM
The functional requirement was to display an error message on a form as long as the specific field is not populated. Once it is populated the message disappears. In the test It opens the form with the field blank, making it a requirement to show the error message. The error message was not displayed when the form loaded, so the test failed. So i wrote the onLoad client script, and thanks to you and another gentleman, my rookie coding errors were fixed to resolve my situation. The test now passes with the correct script, I just had some errors in it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 10:56 PM
That's why I am asking. Because now we were only able to look at a piece of code and point out wat was wrong. Though actually, knowing the functional requirement, we could have helped you in an other direction. onLoad Client Script is a wrong choice here. Sure it can work, though looking at performance etc, its a wrong choice. Looking at your requirement, this should have been solved Server Side, not Client Side.
Kind regards,
Mark
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
06-16-2023 11:23 AM - edited 06-16-2023 11:23 AM
The way the script is written now is going to run when the form loads (onLoad script). Are you sure you want it to run this when the form first loads versus when it's submitted?
This will do it if you do want it to run onLoad:
function onLoad() {
//Type appropriate comment here, and begin script below
var taxonomy = g_form.getValue('spm_taxonomy_node');
if(!taxonomy) {
g_form.addErrorMessage('Service cannot move beyond pipeline phase and approved status until a taxonomy node is set.');
}
}
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven