Call Script Include In UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 04:39 AM
Hello Experts,
I have written below UI action script to delete records .but I am not able to call my script include.plesse guide me on this.
Thank you.
//UI action
function cleanup() {
var c = confirm("Are you sure?");
g_form.addInfoMessage(c);
if (c) {
var ga = new GlideAjax('MyGlideAjaxScriptInclude'); // Replace with the name of your Script Include
ga.addParam('sysparm_name', 'CleanUPEvents');
}
// var ga = new GlideAjax('MyGlideAjaxScriptInclude'); // Replace with the name of your Script Include
// ga.addParam('sysparm_name', 'CleanUPEvents'); // Specify the server-side method to call
// ga.getXMLAnswer(function(response) {
// if (response === 'success') {
// alert("Server Response: " + response);
// setTimeout(function() {
// location.reload(true);
// }, 1000); // Reload the page after 1 second
// } else {
// alert("Server Response: " + response);
// }
// });
// }
}
Script Include client callable:
var MyGlideAjaxScriptInclude = Class.create();
MyGlideAjaxScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
CleanUPEvents: function() {
try {
var gr = new GlideRecord('u_ma_frm_event');
gr.addQuery('u_ma_fld_state', 'closed');
gr.query();
gr.deleteMultiple();
return true;
} catch (ex) {
gs.error("An error occurred in CleanUPEvents: " + ex);
return false;
}
},
type: 'MyGlideAjaxScriptInclude'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 04:50 AM
Hi @Mark Wood
Try defining your function in the script include with prefix "ajax"
Eg: ajaxFunctionName, ajaxCleanUPEvents
Hope this helps you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 04:51 AM
Hi @Mark Wood,
Try this:
//UI action
function cleanup() {
var c = confirm("Are you sure?");
g_form.addInfoMessage(c);
if (c) {
var ga = new GlideAjax('MyGlideAjaxScriptInclude'); // Replace with the name of your Script Include
ga.addParam('sysparm_name', 'CleanUPEvents');
ga.getXML(getAnswer);
function getAnswer(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=== 'success') {
alert("Server Response: " + response);
setTimeout(function() {
location.reload(true);
}, 1000); // Reload the page after 1 second
} else {
alert("Server Response: " + answer);
}
}
}
}
Script Include client callable:
var MyGlideAjaxScriptInclude = Class.create();
MyGlideAjaxScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
CleanUPEvents: function() {
try {
var gr = new GlideRecord('u_ma_frm_event');
gr.addQuery('u_ma_fld_state', 'closed');
gr.query();
gr.deleteMultiple();
return true;
} catch (ex) {
gs.error("An error occurred in CleanUPEvents: " + ex);
return false;
}
},
type: 'MyGlideAjaxScriptInclude'
});
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 04:52 AM
So what debugging have you done so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 04:54 AM
You need to call the getXMLParse function to execute the Glide Ajax. Use the below script in UI Action
function cleanup() {
var c = confirm("Are you sure?");
g_form.addInfoMessage(c);
if (c) {
var ga = new GlideAjax('MyGlideAjaxScriptInclude'); // Replace with the name of your Script Include
ga.addParam('sysparm_name', 'CleanUPEvents');
ga.getXMLAnswer(parseData);
function parseData(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == "true"){
// Write your code for true response
}
else{
// Write your code for false response
}
}
}
}
Palani