- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 02:49 AM
Hello,
I am trying to call script include function from within UI script (below code between comments "SCRIPT INCLUDE CALL - BEGIN" and "SCRIPT INCLUDE CALL - END" however it seems it is not working as the script include should trigger and event and return a value as well of which nothing works.
I am just wondering whether calling GlideAjax from within UI script is the right way and whether there is more "best practise" way to call the function testFunction in the script include.
Appreciate your help,
Milan
My UI script:
var Story93_ui_script = function(dialogWindow) {
//alert('Hello from UI script story 93');
var $btnCancelDialog = null;
var $frmSubmitDialog = null;
_init();
function _init() {
_initForm();
_initEventHandlers();
}
function _initForm() {
$btnCancelDialog = $j("#cancel_dialog");
$frmSubmitDialog = $j("#bucketStuff");
}
function _initEventHandlers() {
// cancel button event
$btnCancelDialog.click(function(event) {
submitCancel(event);
});
// form submit event
$frmSubmitDialog.submit(function(event) {
onFormSubmit(event, this);
});
function submitCancel(event) {
//alert('Story 93 - Slush bucket will be closed.');
event.preventDefault();
// tear down the dialog
dialogWindow.destroy();
return false;
}
function onFormSubmit(event, form) {
//alert('Story 93 - Submit button clicked.');
event.preventDefault();
var slushEmails = [];
var slushEmails_right_slush_bucket_side = form.slushEmails_right;
alert("Number of emails chosen: " + slushEmails_right_slush_bucket_side.length);
for (var i=0; i < slushEmails_right_slush_bucket_side.length; i++) {
slushEmails.push(slushEmails_right_slush_bucket_side[i].innerHTML);
}
//SCRIPT INCLUDE CALL - BEGIN
var gajx = new GlideAjax('Story93_script_include');
gajx.addParam('sysparm_name', 'testFunction');
gajx.addParam('sysparm_email_array', slushEmails);
gajx.getXML(SiParse);
function SiParse(response) {
var answerFromXML = response.responseXML.documentElement.getAttribute('answer');
alert(answerFromXML);
}
//SCRIPT INCLUDE CALL - END
alert(JSON.stringify(slushEmails));
dialogWindow.destroy();
return true;
}
}
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 03:36 AM
Get rid of the eventQueue and just log out your message. In this context there is no current object so the arguments in your eventQueue are undefined which might be bugging out your code and stopping the return from executing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 02:56 AM
Hi Milan,
Is your script include client callable?
Any error you see in system logs related to the script include?
Is that alert coming or not i.e. answerFromXML?
function SiParse(response) {
var answerFromXML = response.responseXML.documentElement.getAttribute('answer');
alert(answerFromXML);
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
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-06-2019 03:06 AM
Hello,
yes, it's client callable.
The alert from answerFromXML but empty, which means its not getting the return value from script include, the returned value in alert is null.
Didn't find anything in error logs.
Thanks a lot,
Milan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 03:04 AM
Hello Milan,
Try adding logs to in script include and UI script as well.
can you paste a screenshot for script include?
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2019 03:08 AM