- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 09:40 PM
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::
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:
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2016 08:51 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 10:43 PM
Hi,
Can you tell me the scope of your client script.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 10:54 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 11:06 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 11:19 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 11:27 PM
The scope of the client script is there in the record itself. it should be the same as the scope of the script include