Prevent form submission dependent on GlideAjax response in onSubmit Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 07:30 AM
I have the following onSubmit client script on the Incident table. It is intended to prevent the user Resolving (state = 6) the incident if a linked Outage record does not have an end date. If I set an Incident with an open Outage record to Resolved and save I see the Error Message below. It appears at the top of the screen for a moment, then disappears and the Incident is saved as Resolved. I am new to Glide Ajax and may be misunderstanding how to process the response. I expected the message to stay on the screen until the user closed it, and the that the record would not save.
Any help welcome.
Many thanks
Ruth
function onSubmit() {
if(g_form.getValue('state') != 6) {
return;
}
var inc = g_form.getUniqueValue();
var ga = new GlideAjax('DfE_CheckOutages');
ga.addParam('sysparm_name', 'checkOutages');
ga.addParam('sysparm_incident', inc); //sys_id for INC0010847
ga.getXML(ajaxResponse);
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true') {
g_form.addErrorMessage('There is at least one open Outage record linked to this Incident. Please enter the End date(s) before you resolve this Incident');
return false;
}
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 08:24 AM
Hi @ruth3brown
Maybe try an alert rather then a message
return false;
Try:
function onSubmit() {
if(current.state.changesTo == 6) { //you may need to use incident_state
var inc = g_form.getUniqueValue();
var ga = new GlideAjax('DfE_CheckOutages');
ga.addParam('sysparm_name', 'checkOutages');
ga.addParam('sysparm_incident', inc); //sys_id for INC0010847
ga.getXML(ajaxResponse);
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true') {
alert('There is at least one open Outage record linked to this Incident. Please enter the End date(s) before you resolve this Incident');
return false;
}}}}
Hope this helps
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2018 02:05 AM
Thanks Dave, I originally had an alert, it displays the message but still goes ahead and saves the Incident record. I don't know how to prevent the Incident record from being submitted. I found another post on a forum that suggested I should use getXMLWait instead. I will look into it but thought it was not generally recommended.
Any other ideas welcome.
Kind Regards
Ruth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2018 02:28 AM
HI,
Use:
g_form.submitted = false;
return false;
Thanks,
Ashutosh Munot