GlideAjax and onSubmit catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2014 08:27 AM
Hey everyone,
Im having a difficult time with getting an onSubmit catalog client script to work properly. it is meant to validate the dates entered by the user. Im ramming my head into the wall trying to find out whats going on, so i thought that maybe someone has a reason as to why what I have wont work.
The alert on line 23 always displays true for answer and the alert on line 32 always displays null for answer.
Is there a conflict that i dont know about when it comes to onSubmit Catalog Client Scripts and Ajax calls?
function onSubmit() { //This script validates 2 things about the times entered by the user var start = g_form.getValue('start_date'); var end = g_form.getValue('end_date'); //is start before the end? var ajax = new GlideAjax('AjaxUtils'); ajax.addParam('sysparm_name','checkEndDate'); ajax.addParam('sysparm_start_date', start); ajax.addParam('sysparm_end_date', end); ajax.getXML(checkDate); //is start after now? var ajax2 = new GlideAjax('AjaxDateDiffCalc'); ajax2.addParam('sysparm_name','dateDiffNow'); ajax2.addParam('sysparm_newDate', start); ajax2.getXML(checkStart); //callback functions function checkDate(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); alert ("start before end? " + answer); if (!answer) { g_form.showFieldMsg('end_date', 'The end date must occur after the start date.','error',true); return false; } } function checkStart(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); alert("Start is " + answer + " seconds after now"); if (answer <= 0) { g_form.showFieldMsg('start_date', 'The start date must not be set to a time prior to now.','error',true); return false; } } }
the previously existing Script includes that i was attempting to use are as follows:
AjaxDateDiffCalc: var AjaxDateDiffCalc = Class.create(); AjaxDateDiffCalc.prototype = Object.extendsObject(AbstractAjaxProcessor, { dateDiffNow: function() { var diff = gs.dateDiff(gs.nowDateTime(), this.getParameter('sysparm_newDate'), true); return diff; },
and
checkEndDate : function(startDate, endDate) { if (typeof(startDate) == 'undefined') { startDate = this.getParameter('sysparm_start_date'); } if (typeof(endDate) == 'undefined') { endDate = this.getParameter('sysparm_end_date'); } return(gs.dateDiff(startDate, endDate, true) >= 0); },
This is from the class 'AjaxUtils'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2018 11:28 PM
I found a solution that worked for me in a scoped app. Feel free to try it out. It's not very pretty, but basically I just call the action name agian in the callback and with a parameter ensure that the check is only done once:
function onSubmit() {
// If licence check is set to ignore, just return true and therefore submit the record
if (g_scratchpad.ignoreLicenceCheck){
g_scratchpad.ignoreLicenceCheck = false;
return true;
}
// Asynchronous glide ajax call to check something on server on submit
var ga = new GlideAjax('ContractHelper');
ga.addParam('sysparm_name', 'checkIfContractHasLicence');
ga.addParam('contract_sysid', g_form.getUniqueValue());
ga.getXMLAnswer(doStuff);
// Always return false to prevent form submit initially, we resubmit the form in the glide ajax callback
return false;
function doStuff(result) {
if (result == 'false'){
// Check from server returned false as no licence was found. Ask the user if he still wants to continue
var confirmResult = confirm('Es wurde noch keine detaillierte Lizenzvergütung erfasst. Trotzdem fortfahren?');
if (confirmResult){
// User confirmed the submit, therefore set the flag and resubmit the form
g_scratchpad.ignoreLicenceCheck = true;
gsftSubmit(null, g_form.getFormElement(), 'contract_next'); // 'Action name' of the UI Action to call
}
} else {
// Everything good, set the flag and resubmit the form
g_scratchpad.ignoreLicenceCheck = true;
gsftSubmit(null, g_form.getFormElement(), 'contract_next'); // 'Action name' of the UI Action to call
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2018 11:36 PM
Hi,
I could not find solution to this as getXMLWait does not work in scoped app. But you can try the following:
- create a On Submit (catalog) client script in the global scope and attached it to your catalog item. There we have access to getXMLWait().
Thanks