Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

g_form.submit() is not working with spModal PoupUp Window

Pritam Khude
Tera Contributor
Hello Community,

I have a Catalog Client Script (onSubmit) running in Service Portal.
When a user selects Yes on a variable and no attachment is present, I display an spModal with two buttons:

  • Okay → stay on the form (do not submit)
  • Cancel → submit the request

I call g_form.submit() when the user clicks Cancel. However, that triggers my onSubmit again, the same condition is met, the modal opens again, and I end up in a submission loop. and form not getting submit.



function
onSubmit() {

    var errorAppear = g_form.getValue('gw_mi_did_any_errors_appear');

    if (errorAppear === 'Yes' && (this.document.getElementsByClassName('get-attachment').length == 0)) {
      spModal.open({
            title: 'Attachment recommended',
            message: 'You mentioned an error occurred, if possible please attach a screenshot of the error',

            buttons: [{
                    label: 'Okay',
                    primary: true
                },
                {
                    label: 'Cancel',
                    primary: true
                }
            ]
        }).then(function(button) {
            if (button.label === 'Cancel') {
                g_form.addInfoMessage("Submit");
                g_form.submit();
                return true;
            }
        });

        return false; // Block original submit until user choose
    }
    return true; // Allow normal submit if condition not met
}
10 REPLIES 10

Hello @Aditya_hublikar,

Thank you for your response.

I used Flag variables also but the code is not working

if user clicks the Cancel button, the form does not get submitted—it goes into a loop again if.
 
Thank you