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

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

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.

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

LinkedIn