Onsubmit client script needs to return false , when child function returns false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2023 08:32 PM
Hi All,
I am trying below onsubmit client script , when the functions(verifystartdate(response) and verifyenddate(response)) inside onsubmit return false , i want onsubmit function to return false so that the form is prevented from updating or committing.
Kindly suggest if this is possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2023 08:33 PM
Client Script:
function onSubmit() {
//g_form.clearMessages();
var num = g_form.getReference('task_number',func);
var beginDate = g_form.getValue("begin");
var endDate = g_form.getValue("end");
function func(num)
{
if(num.number.toString().indexOf('CHG')>-1)
{
var ga = new GlideAjax('ChangeRequestCheckBeginDate'); //client callable script include
ga.addParam('sysparm_name', 'checkStartofChange'); //function name on the script include
ga.addParam('outageStartDate', beginDate); // the begin date selected by the user
ga.addParam('changeId', g_form.getValue('task_number')); //changeID - to query and compare with the change start date.
ga.getXML(verifystartdate);
}
}
function verifystartdate(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false'){
//alert('Outage Begin date should be within the Change Planned Window');
g_form.addErrorMessage(getMessage("Outage Begin date should be within the Change Planned Window"));
//g_form.showFieldMsg('begin','Outage Begin date should be within the Change Planned Window','error');
//g_form.clearValue('begin'); //to clear out the value selected by the user
return false;
}
}
var num1 = g_form.getReference('task_number',func1);
function func1(num1)
{
if(num1.number.toString().indexOf('CHG')>-1)
{
var ga = new GlideAjax('ChangeRequestCheckEndDate'); //client callable script include
ga.addParam('sysparm_name', 'checkendofChange'); //function name on the script include
ga.addParam('outageendDate', endDate); // the begin date selected by the user
ga.addParam('changeId', g_form.getValue('task_number')); //changeID - to query and compare with the change start date.
ga.getXML(verifyenddate);
}
}
function verifyenddate(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false'){
//alert('Outage End date should be within the Change Planned Window');
g_form.addErrorMessage(getMessage("Outage End date should be within the Change Planned Window"));
//g_form.showFieldMsg('end','Outage End date should be within the Change Planned Window','error');
//g_form.clearValue('end'); //to clear out the value selected by the user
return false;
}
}
}