Uncaught ReferenceError: g_form is not defined

ramireddy
Mega Guru

I wants to display an sample error message from client side on the web page. So, I created following test page. But it's showing the error in browser console tab, "Uncaught ReferenceError: g_form is not defined".

Here is my page:

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:ui_form>

  <input type="button" onclick="return validate();" value="Save"/>

</g:ui_form>

</j:jelly>

My client script:

function validate()

{

  alert("Validating");

  g_form.addErrorMessage('This is an error');

  return false;

}

On click of the button, I am getting the alert message. But it's not displaying the error message on the form. What am I missing here?

1 ACCEPTED SOLUTION

Hi Ram,



Can you try something like this in your client script




  1. function validate()  
  2. {  
  3. var g_form=new GlideForm(); // I have added this
  4. alert("Validating");  
  5.   g_form.addErrorMessage('This is an error');  
  6.   return false;  
  7. }  



Thanks


Srini



Please mark this response as correct/helpful if it does so.


View solution in original post

4 REPLIES 4

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Not sure that g_form is working on a ui page



take a look here. There is a couple of workarounds, but sadly you ain't alone...



g_form not initialized on a custom CMS page


Thank you,



Is there any alternative way in servicenow, we can display a message to user on client-side(apart from javascript alerts)??



Thanks


Rami Reddy


Hi Ram,



Can you try something like this in your client script




  1. function validate()  
  2. {  
  3. var g_form=new GlideForm(); // I have added this
  4. alert("Validating");  
  5.   g_form.addErrorMessage('This is an error');  
  6.   return false;  
  7. }  



Thanks


Srini



Please mark this response as correct/helpful if it does so.


Thank you Srinivas,



Worked like charm..