how to abort action on submit using client script

max_danielewicz
Giga Expert

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

12 REPLIES 12

Hi,

The syntax for scratchpad is wrong

Use

g_scratchpad.canSubmit = true;

 g_form.scratchpad is incoorect way of using scratchpad variable.

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Afternoon,

 

Thanks for the quick reply, I did try that as well but without luck. I'm trying to do it with a glideAjax but looks to only work with a on Display Business Rule from the examples provided online.

 

Kind Regards

Ashley

Can you please open separate thread and share more details, as this is old thread you may not get response from other community members. Also it will span exiting subscribers of this question.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande