The Zurich release has arrived! Interested in new features and functionalities? Click here for more

onSubmit script g_modal popup saving form when popup appears

Khalnayak
Tera Guru

Hello,

I have the following onSubmit client script, and it presents a modal popup for end users when conditions are met.

This is for native Ui and agent workspace.

Works fine in native, it prompts the user with modal and only submits form when user selects yes.

Whereas in workspace, when the modal popup appears the form saves at the same time.

How can I prevent the form from saving in workspace until the modal has not been actioned, i.e. yes/no selected.

here is my script for HR cases:

function onSubmit() {

    var subjectPersonValue = g_form.getValue('subject_person');
    var openedForValue = g_form.getValue('opened_for');
    var openedFor = g_form.getControl('opened_for');



    var url = top.location.href;
    if (url.indexOf('workspace') <= -1) { // if using native UI run this code

        if (openedFor.changed) {
            if (subjectPersonValue == openedForValue) {

                if (g_scratchpad._action_confirmed) {
                    return true;
                }
					// Render GlideModal window
                var dialog = new GlideModal('glide_modal_confirm', false, 400);
                dialog.setTitle(new GwtMessage().getMessage('Opened for Changed to Subject Person'));
                dialog.setPreference('body', new GwtMessage().format("You have set the Opened For to the Subject Person, which will grant them access to view the Case - are you sure?"));
                dialog.setPreference('focusTrap', true);
                dialog.setPreference('onPromptComplete', doComplete);
                dialog.setPreference('onPromptCancel', doCancel);

                dialog.render();

                return false;

                function doComplete() {
                    g_scratchpad._action_confirmed = true;
                    gsftSubmit(null, g_form.getFormElement(), g_form.getActionName());
                }

                function doCancel() {

                }

            }
        }
    } else if (url.indexOf('workspace') > -1) { // if using workspace run this code

        if (g_scratchpad.openedFor != g_form.getValue('opened_for')) { // If opened for value has changed

            if (subjectPersonValue == openedForValue) {
				// Render Modal window
                var msg = "You have set the Opened For to the Subject Person, which will grant them access to view the Case - are you sure?";
                g_modal.confirm(getMessage("Opened for Changed to Subject Person"), msg, function(confirmed) {

                    if (confirmed) {
                        g_form.save();
                    }
                });
            }


        }

    }


}
18 REPLIES 18

Vijayalakshmi P
Kilo Sage

I am facing the same issue. Pls post here, if you find the solution.

Thanks.

-O-
Kilo Patron
Kilo Patron

The script needs to return false to cancel submission, but the part handling workspace does not return anything at all at any time.

Khalnayak
Tera Guru

@Ankur Bawiskar @Pradeep Sharma @Mark Roethof @Dan Bruhn @Jaspal Singh @asifnoor @Ashutosh Munot @Harshvardhan @Allen Andreas @Maik Skoddow @Dan H @shloke04 @Smudge @Hitoshi Ozawa @Anil Lande @Rohila V @Michael Jones - GlideFast @Anurag Tripathi 

please advise here

Khalnayak
Tera Guru

@Ankur Bawiskar @Pradeep Sharma @Mark Roethof @Dan Bruhn @Jaspal Singh @asifnoor @Ashutosh Munot @Harshvardhan @Allen Andreas @Maik Skoddow @Dan H @shloke04 @Smudge @Hitoshi Ozawa @Anil Lande @Rohila Voona @Michael Jones - GlideFast @Anurag Tripathi 

can you help me here please.