Uncaught ReferenceError: GlideAjax is not defined

mahdyy
Kilo Contributor

Hi,

I am new to ServiceNow and trying some hands on GlideAjax/GrideRecord scrtpting. I have created a new "Script Include" with "Client Callable" => TRUE. While trying to invoke the same from the client web browser using JavaScript using "GlideAjax", I am facing the error - "Uncaught ReferenceError: GlideAjax is not defined" I have even tried to use "GlideRecord" but getting the same reference error.

Below is the Script Include I have defined in the system::

find_real_file.png

The client-side script I have written to call the Script Include is as below:

                  var ga = new GlideAjax('getCallerData');

                  ga.addParam('sysparm_name','getSysID');

                  ga.addParam('sysparm_phone_number',"(080) 224-1097");

                  ga.getXMLWait();

                  alert(ga.getAnswer());

The error screen-shot is:

find_real_file.png

Am I missing in enabling something which will then include the necessary javascript libraries related to GlideAjax/GlideRecord in the client side?

I am using "glide-helsinki-03-16-2016__patch4-08-10-2016_08-27-2016_1002".

Thanks in advance.

Regards

Mahendra

1 ACCEPTED SOLUTION

Hi Mahendra,



I have replied to your email with necessary links and it worked perfectly fine. I have created a client script in incident form view and it is working as expected.


View solution in original post

20 REPLIES 20

prithvirajchaud
Mega Expert

Hi,



Can you tell me the scope of your client script.



Thanks


Hi Prithviraj,



I am not sure where to find the scope of my client script; but Application scope was set to GLOBAL.


find_real_file.png



Regards


Mahendra


9741333111


Mahendra,



Surely typos caused the errors



Script Include



var getCallerData = Class.create();


getCallerData.prototype = Object.extendsObject(AbstractAjaxProcessor, {




  getSysID: function() {


  var gr = new GlideRecord('customer_contact');


  gr.addQuery('phone', this.getParameter('sysparm_phone_number'));


  gr.query();


  if (gr.next()) {


  return gr.sys_id;


  }


  return 'no-match';


  },


      type: 'getCallerData'


});




Client Script



function onLoad() {


    //Type appropriate comment here, and begin script below


  var ga = new GlideAjax('getCallerData');


  ga.addParam('sysparm_name','getSysID');


  ga.addParam('sysparm_phone_number',"(974) 133-3111");


  //ga.getXMLWait();


  ga.getXML(HelloWorldParse);



function HelloWorldParse(response) {


    var answer = response.responseXML.documentElement.getAttribute("answer");


    alert(answer);


}


// alert(ga.getAnswer());


   


}



use this. it will work.


mahdyy
Kilo Contributor

Hi Prasun,



I have used the above code, but it didn't worked in my environment 😞


I am getting the same error "Uncaught ReferenceError: GlideAjax is not defined" in the browser console and the script is exiting at line-1 itself, even before going to the addParams() function.


Looks like it is the environment issue from my side. Can you please help in which scope the client browser should run inorder to make use of GlideAjax/GlideRecord calls? Also request to suggest how to set the client scope.


I am running this client-side javascript (calling GlideAjax) from the HTML page (attached) which is being invoked by "OpenFrame" window.



Regards


Mahendra


9741333111


The scope of the client script is there in the record itself. it should be the same as the scope of the script include