onSubmit still submitting despite using return False?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2022 11:01 AM
Hi,
I have a onSubmit client script that is making a glideajax call to get information from another table. Then depending on that information, it may say the option on the form the user selected is an error and should be fixed, then prevent the form from being submitted. The alert is working properly and I am using 'return false;' but the form is still getting submitted. Any ideas why this is?
function onSubmit(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var recordTask = g_form.getDisplayBox('task').value;
if(recordTask.indexOf('INCTSK') >= 0){
var incidentTask = new GlideAjax('incidentTasks');
incidentTask.addParam('sysparm_name', 'checkCustomerCategory');
incidentTask.addParam('sysparm_task', g_form.getValue('task'));
incidentTask.getXML((parseObject));
}
function parseObject(response, dontSubmit){
var itdcostcenter = g_form.getDisplayBox('u_itd_cost_center').value;
var answer = response.responseXML.documentElement.getAttribute("answer");
var myObj = JSON.parse(answer);
var custCat = myObj[0];
var feeType = myObj[1];
if(feeType != 'LABOR' && itdcostcenter.includes('LABR')){
alert("ERROR! The task's "+g_form.getDisplayBox('task').value+" customer category is "+ custCat + " and its fee type is "+feeType +" but the ITD Cost Center selected is "+itdcostcenter+". Please select an ITD Cost Center that is appropriate for the customer category. This time worked record will not be submitted. ");
//Abort the submission
return false;
}else if(feeType == 'LABOR' && itdcostcenter.toUpperCase().indexOf("LABR") == -1){
alert("ERROR! The task's "+g_form.getDisplayBox('task').value+" customer category is "+ custCat + " and its fee type is "+feeType +" but the ITD Cost Center selected is "+itdcostcenter+". Please select an ITD Cost Center that is appropriate for the customer category. This time worked record will not be submitted.");
//Abort the submission
return false;
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2022 11:09 AM
Hi,
If this is a normal client script, then you shall use getXmlWait, which will wait for the response. However, the drawback of this is, this is not supported in Service Portal.
For service portal, wahtever the validation is, the recommended way is to write this on a onChange client script and throw the error.
Related link: https://community.servicenow.com/community?id=community_article&sys_id=e37f2072db9fd0103daa1ea668961...
Mark the comment as a correct answer and also helpful if this has helped to solve the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2022 01:21 PM
This won't be used in Service Portal, so no problem there. However I tried changing incidentTask.getXML((parseObject)); to incidentTask.getXMLWait((parseObject)); and got no change. How am I supposed to use the getXMLWait function? I havent been able to find much documentation for getXMLWait().