GlideAjax call in onSubmit Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2013 04:07 PM
Hello fellow Service-Now folk,
I've encountered an issue within an onSubmit client script and am looking for a workaround or any ideas.
It appears that the Ajax return is triggering onSubmit's "return true" condition. At first I thought the issue was incorrect variable scoping. After some messing around I tried capturing the response inside an object but onSubmit seems to still detect the Ajax return no matter how I try to layer it. Finally I commented out most of the script and just left the XML response. The alert with the XML response briefly appears on the page before the item is successfully submitted (goes to page 3 of the order guide). This is still triggering a return true condition even though there is no explicit return statement left in the script!!
Have you seen this before? Is there a work around for this behavior? I am trying to perform date validation on an order guide item before submission.
function onSubmit() {
alert("onsubmit started");
var objContainer = {};
alert("Object container initiated.");
objContainer.callback = function(data) {
objContainer.server_date = data.responseXML.documentElement.getAttribute("answer");
alert("Object should have XML response: " + objContainer.server_date);
};/*
objContainer.form_date = g_form.getValue('u_loststolen_datetime');
objContainer.callback.ret = function () {
if ( objContainer.form_date > objContainer.server_date ) {
alert("server_date greater than form_date, cannot submit");
alert("form date = " + objContainer.form_date + "\nserver_date =" + objContainer.server_date);
//return 'return false';
}else{
//return 'return true';
}
};
*/
var sdate = new GlideAjax('ValidateDateTime');
sdate.addParam('sysparm_name','validate');
sdate.getXML(objContainer.callback);
/*
if (objContainer.form_date == "") {
//return true;
}else{
//objContainer.callback.ret();
}
*/
}
//Script Include:
var ValidateDateTime = Class.create();
ValidateDateTime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validate: function() {
var today = gs.now();
return today;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2013 08:42 PM
I think you'll have better luck using 'getXMLWait' if you're using glideAJAX in an onSubmit script. The 'getXML' call you're using is asynchronous (which is usually desirable) but it doesn't work well in the onSubmit scenario because the submit blows right past it before the response is returned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2013 09:27 AM
Thanks Mark I'll give that a shot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2013 04:16 PM
I wasn't able to get it to work using either getXML() nor getXMLWait(). Instead I used an onChange() on the item to make the Ajax call and set a value on a hidden variable on the form.
The onSubmit() now checks the value of the hidden variable instead of making the Ajax call.
