Receiving error messageGlideAjax not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 08:45 AM
I'm having an issue calling script include from a UI Action. I thought I would test a simple script from Background Script that returns department name from sys_user table record. Below is the client script I'm running from Background Script and the script include which is set to 'Client callable'. Both actions are in Global scope. Whenever I run the script I receive an error indicating 'GlideAjax' is not defined. It use to be that when typing the declaration line (var ga = new GlideAjax('script_include_name'), the whole GlideAjax declaration would turn italic after completing the command. This is not the case now. The script include name turns italic but GlideAjax does not (var ga = new GlideAjax('script_include_name'). I can confirm that 'AbstractAjaxProcessor' is in the system.
Any help is greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 12:10 PM
Hi Tera Expert,
Thanks for this suggestion but I have already tested the script include using this approach and it works. My failure is with using GlideAjax. I never get to the script include function because of the ''GlideAjax' is not defined' error from within the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 12:39 PM
Hi @Jeff96 ,
If you try from the background script you will get the same error of GlideAjax being undefined as it works on client side only. \
You need to create a Onload/Onchange client script & test it from there for sure it will work keeping in mind the change which @Bert_c1 highlighted "You have "sysparam_name" and "sysparam_id" in the client script but then access "sysparam_user" in you script include".
Please mark my answer helpful if it helps you resolve your issue
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2023 12:27 PM - edited 09-18-2023 03:09 PM
Hi Jeff96,
Here's an example where the client_script successfully calls the script include.
function onSubmit() {
//Type appropriate comment here, and begin script below
alert("client script is running");
var sdt = g_form.getValue('start_date');
var edt = g_form.getValue('end_date');
var ga = new GlideAjax('global.ChangeOutageValidate');
ga.addParam('sysparm_name', 'getOutageDetails');
ga.addParam('sysparm_startdate', sdt);
ga.addParam('sysparm_enddate', edt);
ga.addParam('sysparm_sysid', g_form.getUniqueValue());
ga.getXML(pop);
function pop(response) {
var bp = (response.responseXML.documentElement.getAttribute("answer"));
alert("response = " + bp);
// g_form.setValue('follow_up', bp);
}
}
Set parameters there. Access the same in the script include:
var ChangeOutageValidate = Class.create();
ChangeOutageValidate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOutageDetails: function() {
var result = true;
var cR_sys_id = this.getParameter("sysparm_sysid");
var cR_start_date = this.getParameter("sysparm_startdate");
var cR_end_date = this.getParameter("sysparm_enddate");
var outageRec = new GlideRecord("task_outage");
outageRec.addEncodedQuery("task=" + cR_sys_id);
outageRec.query();
gs.info("getOutageDetails: Found " + outageRec.getRowCount() + " outage records.");
while (outageRec.next()) {
if(!JSUtil.nil(outageRec.outage.begin) && !JSUtil.nil(outageRec.outage.end))
{
var d1 = new GlideDateTime(outageRec.outage.begin.getDisplayValue());
var d2 = new GlideDateTime(cR_start_date);
var d3 = new GlideDateTime(outageRec.outage.end.getDisplayValue());
var d4 = new GlideDateTime(cR_end_date);
gs.info("getOutageDetails: ob = " + d1 + ", pb = " + d2 + ", oe = " + d3 + ", pe = " + d4);
if(d1 >= d2 && d3 <= d4){
result = true;
}
else{
result = false;
}
}
else{
result = false;
}
}
gs.info("getOutageDetails: returning: " + result);
return result;
},
type: 'ChangeOutageValidate'
});
Notice how the script include uses the same parameters, by name, as defined in the client script. You have "sysparam_name" and "sysparam_id" in the client script but then access "sysparam_user" in you script include. Maybe this working example will help. there are OOB working examples in your instance.
Also, if you post code as text, folks here can easily reproduce. By 'cut-and-paste'.