- 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:27 AM
According to the test parameters, it is supposed to show when the form loads. The test fails because the form loads without the message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 11:29 AM
I tested the script above in my personal dev instance and it works as expected. So if that is what you need, give it a try.
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:49 AM
If the script above helped, just mark it as Accepted Answer or Correct. Otherwise, mark another post as the accepted answer to close the topic out.
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:37 AM
Thank you guys, my issue has been resolved and it now appears my test suite is passing. Good advice and I learned something.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 11:38 AM
Oke good to hear!
Please close this topic.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field