how to abort action on submit using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 07:21 AM
Hi community,
i hope everyone is ok.
SITUATION
i created a catalogue client script that runs on change, and works. However, it should be running "on submit" instead, but i don't know how to make it work.
the client script calls a script include which returns a value and depending on the value i would display a message and abort the action or proceed.
PROBLEM
i cannot make it work !!
Here is the code (attached) used in the "on change" that i need to transform for the "on submit". could you pls help me to change it so it works on submit?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var sdt = g_form.getValue("start_dt"); //Choose the field to add time from
var gt = g_form.getValue("guest_type");
var stayhs = g_form.getValue("hdays"); //The amount of time to add addtime
var addtype = 'hour'; //The time type. Can be second, minute, hour, day, week, month, year.
var ajax = new GlideAjax('ABCDateUtils');
ajax.addParam('sysparm_name','CarParkSpace');
ajax.addParam('sysparm_fdt', sdt);
ajax.addParam('sysparm_gtype', gt);
ajax.addParam('sysparm_addtype', addtype);
ajax.addParam('sysparm_stayh', stayhs);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if(answer == 'out') {
alert('Your hours selection has exceeded the amount of time you could stay for the day. Please select less hours.');
g_form.clearValue('hdays');
**should abort
}
if(answer == null) {
alert('Unfortunately, there are not available spots for the selected date and time. Your request cannot be submitted.');
g_form.clearValue('hdays');
g_form.clearValue('start_dt');
**should abort
}
if(answer != null && answer != 'out') {
alert('Car spce ' + answer + ' will be reserved for you for the selected date and time. Please SUBMIT the form.');
}
g_form.setValue('spacename', answer);
** should submit
}
}
kind regards,
max
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 07:24 AM
Hi,
To abort in client script just use the line below
return false;
-Anurag

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 07:25 AM
Hi,
just use return false; whenever you want to abort submission.
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 07:26 AM
The modified script would be:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var sdt = g_form.getValue("start_dt"); //Choose the field to add time from
var gt = g_form.getValue("guest_type");
var stayhs = g_form.getValue("hdays"); //The amount of time to add addtime
var addtype = 'hour'; //The time type. Can be second, minute, hour, day, week, month, year.
var ajax = new GlideAjax('ABCDateUtils');
ajax.addParam('sysparm_name','CarParkSpace');
ajax.addParam('sysparm_fdt', sdt);
ajax.addParam('sysparm_gtype', gt);
ajax.addParam('sysparm_addtype', addtype);
ajax.addParam('sysparm_stayh', stayhs);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if(answer == 'out') {
alert('Your hours selection has exceeded the amount of time you could stay for the day. Please select less hours.');
g_form.clearValue('hdays');
return false; //should abort
}
if(answer == null) {
alert('Unfortunately, there are not available spots for the selected date and time. Your request cannot be submitted.');
g_form.clearValue('hdays');
g_form.clearValue('start_dt');
return false; //should abort
}
if(answer != null && answer != 'out') {
alert('Car spce ' + answer + ' will be reserved for you for the selected date and time. Please SUBMIT the form.');
}
g_form.setValue('spacename', answer);
// do nothing
}
}
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2021 04:46 PM
Hi Anil,
thanks for your suggestion.
i want to modify the client script to convert it to an "on submit" client script.
regards,
Max