popup functionality not working in service portal

kummara _siva
Tera Contributor

Hi All,

I want a popup showing a message and if user clicks okay then form should submit ,if clicks on cancel button it shouldn,t.so i have written catalog client script onsubmit .It is working but the issuse is if user clicks on order button in portal popup is opening and it is submitting form .how to stop that here is the code.

 

 var sys = g_form.getUniqueValue();
    var gaAjax = new GlideAjax('validatedeliverydate');
    gaAjax.addParam('sysparm_name', 'calculateDueDate');
    gaAjax.addParam('sysparm_sysId', sys);
    gaAjax.getXML(DueDate);
    function DueDate(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer) {
            var html = "Estimated delivery Date for this item is " + answer;
            spModal.open({
                title: 'Notify Delivery Date',
                message: html,
                buttons: [{
                    label: 'OK',
                    primary: true,
                    action: function() {
                        g_form.submit();
                    }
                }, {
                    label: 'Cancel',
                    action: function() {
                        spModal.close();
                    }
                }],
            });
        }
    }
}
1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

The short answer is to do this onChange of a mandatory variable instead of onSubmit.  Because Service Portal is asynchronous, the Submit function is not going to wait for the script to go to the server and back.  There are numerous posts on the Community about workarounds for this behavior.  Some of these will work if you are not able to change it to an onChange script for some reason.