onLoad Client Script

Jimmy Morse
Tera Contributor

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:

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   if(g_form.getValue.spm_taxonomy_node == null) {


  g_form.addErrorMessage('Service cannot move beyond pipeline phase and approved status until a taxonomy node is set.');
  }
}
 

I have attached a screenshot of the script. Any assistance is appreciated!

1 ACCEPTED SOLUTION

Steven Parker
Giga Sage

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

View solution in original post

14 REPLIES 14

According to the test parameters, it is supposed to show when the form loads. The test fails because the form loads without the message.

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

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

Jimmy Morse
Tera Contributor

Thank you guys, my issue has been resolved and it now appears my test suite is passing. Good advice and I learned something.

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

LinkedIn