GlideModal on Incident onSubmit Client Script

mmaraj
Tera Contributor

Hi, I put a glidemodal (glide_prompt) on a onsubmit client script. it shows up for a split second but then disappears. Anyone knows why its doing this? I will like to stay on the screen until the user hits submit or cancel

1 ACCEPTED SOLUTION

function onSubmit() {
    var rfc = g_form.getValue('rfc');
    var ga = new GlideAjax('RFCutil');
    ga.addParam('sysparm_name', 'getRFC');
    ga.addParam('sysparm_rfc', rfc);
    ga.getXML(ManagerParse);
return false;
    function ManagerParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        
        var dialog = new GlideModal('glide_prompt', true, 600);
        dialog.setTitle("testing");
		dialog.setPreference("onPromptComplete", function(value){
			g_form.setvalue("work_notes", "testing");
		});
		dialog.setPreference("onPromptCancel", function(value){
			dialog.destroy();
		});
		dialog.render();
	

    }
}

Hi @mmaraj 

Try this

 

Regards

Chaitanya 

View solution in original post

6 REPLIES 6

That workked! Thanks soo much!

Hi @mmaraj ,

 

You  are calling GlideAjax, which is asynchronous. The onSubmit function finishes execution before the ManagerParse callback runs.

Since onSubmit doesn’t return false immediately, the form proceeds to submit, and the modal gets destroyed.

 

Here is updated script:

function onSubmit() {
    // Prevent form submission immediately
    var rfc = g_form.getValue('rfc');
    var ga = new GlideAjax('RFCutil');
    ga.addParam('sysparm_name', 'getRFC');
    ga.addParam('sysparm_rfc', rfc);
    ga.getXML(ManagerParse);

    // Always return false to stop submission until user acts
    return false;

    function ManagerParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");

        var dialog = new GlideModal('glide_prompt', true, 600);
        dialog.setTitle("testing");

        dialog.setPreference("onPromptComplete", function(value) {
            g_form.setValue("work_notes", "testing");
            dialog.destroy();
            // Manually submit the form after user confirms
            g_form.submit();
        });

        dialog.setPreference("onPromptCancel", function(value) {
            dialog.destroy();
        });

        dialog.render();
    }
}

 

Fix:

  • return false; is placed outside the ManagerParse function to stop the form from submitting immediately.
  • g_form.submit(); is called manually after the user completes the modal interaction.

Please mark this as helpful and correct, if this answers your question.

 

Thanks,

Yaswanth