
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2016 11:56 AM
Hi,
I have a form where it's critical that the user submits the correct data the first time. I need to make the following onSubmit client script prompt the user to confirm and abort if they cancel. I know I need a return false; statement somewhere to abort the action, but I can't figure out where to put it or the confirm statement var doIt = confirm('You are about to enter ' + answer + ' hours of ' + timeType + ' time against this task. Are you sure?');
function onSubmit() {
//Type appropriate comment here, and begin script below
var cdt = g_form.getValue('u_start_time'); //First Date/Time field
var sdt = g_form.getValue('u_end_time'); //Second Date/Time field
var dttype = 'hour'; //this can be day, hour, minute, second. By default it will return seconds.
var timeType = g_form.getValue('u_time_allocation');
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_sdt', sdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
TIA!
Karla
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2016 12:24 PM
It's because we're telling it to process in the background, (async).
Change it to a synchronous GlideAjax call and it will work. I just confirmed it.
function onSubmit() {
//Type appropriate comment here, and begin script below
var cdt = g_form.getValue('u_start_time'); //First Date/Time field
var sdt = g_form.getValue('u_end_time'); //Second Date/Time field
var dttype = 'hour'; //this can be day, hour, minute, second. By default it will return seconds.
var timeType = g_form.getValue('u_time_allocation');
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getDateTimeDiff');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_sdt', sdt);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXMLWait();
var answer = ajax.getAnswer();
if (! confirm('You are about to blah blah blah'))
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2019 06:11 AM
var ga = new GlideAjax('NAClaimAjaxURL');
ga.addParam('sysparm_name','DuplicateBookingIncident');
ga.addParam('sysparm_sys_id', g_form.getValue('u_bn'));
ga.getXMLWait();
var returnedAnswer = ga.getAnswer();
alert(returnedAnswer);
if(returnedAnswer == 'false'){
return true;
}
else{
alert('An Incident already exists with this Booking Number associated. Please enter a different Booking Number.');
g_form.clearValue('u_bn');
return false;
}
This code is not working on onsubmit in client script. Please help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2022 05:30 AM
Hi
My requirement is somewhat similar. I am using same logic on change form at new state. If the user selects cancel on confirmation message the client script returns false. The form remains on the same page however on clicking save it moves to next state.
Is it because of some oob functionality or I've inserted return false on wrong position
I have used onSubmit client script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2016 12:28 PM
Yeah, that is what I thought. Thanks chuck

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2016 12:35 PM
Thank you both so much!!! I chose Chuck's answer as the correct one, just because I got his answer first.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2016 12:37 PM
No worries. Need to type faster