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

Hello Milan,

1. first try printing emailList.

EDIT

2. you are pushing json in array. check a log for that as well.

I guess eventQueue is not working. as you are passing current. try commenting eventqueue and try.

It will work for sure

 

Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

I guess eventQueue is not working.

Also check current.number in log? 

Thanks,
Abhishek

Thank you,
Abhishek Gardade

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.

Hello Milan,

1. first try printing emailList.

EDIT

2. you are pushing json in array. check a log for that as well.

I guess eventQueue is not working. as you are passing current. try commenting eventqueue and try.

It will work for sure

Thanks! 
Abhishek Gardade

Thank you,
Abhishek Gardade