GlideAjax not working in UI script

Milan13
Giga Expert

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;

}

}
};

1 ACCEPTED SOLUTION

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.

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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

 

AbhishekGardade
Giga Sage

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

 

Thank you,
Abhishek Gardade

Milan13
Giga Expert

Hello Abhishek,

please see below script include screen shot.

Nothing found in event log either, which probably means the gs.eventQueue method is not called as well as the whole function..

Many thanks,

Milan

 

find_real_file.png