- 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:16 AM
Hi there,
At least g_form.getValue.spm_taxonomy_node is wrong, possibly more, though at least this.
Try:
g_form.getValue('spm_taxonomy_node')
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:18 AM
I do wonder though, since it's an onLoad Client Script, could this also be done Server Side instead of Client Side?
Please explain what your situation is and what you are after. That way we can help you better than just looking at some code and just fixing a line.
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
I am setting up an ATF suite on Service Portfolio Management. One of the tests fails because this error message does not show when the form loads. I am trying to remedy the situation so the test will pass.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 11:27 AM - edited 06-16-2023 11:30 AM
Well at least the script in incorrect. So if you're ATF is about checking that, yeah correct it's failing I guess.
Though the script then also never worked before?
Reading your original post, I would think this is a new Client Script? That's why I'm asking what you are really after. What do you want to achieve functionally? Because it looks odd such a onLoad Client Script.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field