Confirm message on OnSubmit Client Script

Frank Silveira1
Kilo Expert

Hello Experts,

 

I am trying to use a confirm message in my OnSubmit Catalog Client Script on a scoped application but the catalog item submits anyway even if I click on cancel.

The message is currently inside a callback function of an Ajax call that I can't put outside because I need the info to do some validation.

 

Here is the script:

 

var jsonStr = g_form.getValue("u_MRVS");
var obj = JSON.parse(jsonStr);
var transactionDate = obj[0].data_do_debito + " 00:00:00";

function onSubmit() {

    var ga = new GlideAjax('table_name');
    ga.addParam('sysparm_name', 'scriptname');
    ga.addParam('sysparm_schedule_sysID', 'sys_id'); 
    ga.addParam('sysparm_date', transactionDate);
    ga.getXML(businessDays);

    return false;

}

function businessDays(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    var dias = JSON.parse(answer);
    var totaldays = parseInt(dias.totalDias);
    var busDays = parseInt(dias.totalUteis);


    if (totaldays >= 440) {

        alert("Not possible");
        return false;
    }

    if (busDays >= 47 && totaldays < 440) {

        var confirmation = false;

        confirmation = confirm("yes or no question");

        if (confirmation == true) {
            return true;
        } else {
            return false;
        }
    }


}

 

Is there anything I can do to fix this?

 

Thank you in advance.

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi,

Using GlideAjax with onSubmit() is not ideal as by the time output is returned form is already submitted. Suggest you to follow blog that has a workaround to control the behavior.

View solution in original post

1 REPLY 1

Jaspal Singh
Mega Patron
Mega Patron

Hi,

Using GlideAjax with onSubmit() is not ideal as by the time output is returned form is already submitted. Suggest you to follow blog that has a workaround to control the behavior.