Create a Glide Window on an onSubmit Client Script

Dazler
Mega Sage

Hi,

I am working on a glide window on an onSubmit Client script.  The reason I chose this is because if several fields are updated by a certain group of users then I want a popup window that forces them to add a work notes.  I didn't want to create an onChange for each of the fields.

I am testing the concept using the Change Confirmation Reason, I will eventually create my own UI page, but I am just using this to Test.

Here is the script that I have:

function onSubmit() {

    var shortDesc = g_form.getControl('short_description');
    var longDesc = g_form.getControl('description');
    var workNotesComplete = false;
	
    if (shortDesc.changed || longDesc.changed) {

        var dialog = new GlideModal('change_confirm_reason', false, 648, 250);
        dialog.setTitle(new GwtMessage().getMessage('Cancel Change Request'));
        dialog.setPreference('focusTrap', true);
        dialog.setPreference('onPromptComplete', onPromptComplete);
        dialog.setPreference('onPromptCancel', onPromptCancel);
        dialog.on('closeconfirm', onPromptCancel);
        dialog.setPreference('buttonLabelComplete', new GwtMessage().getMessage('OK'));
        dialog.setPreference('buttonLabelCancel', new GwtMessage().getMessage('Cancel'));
        dialog.render();

        return false;

    }

    function onPromptComplete(notes) {
        workNotesComplete = true;
        g_form.setValue("work_notes", notes);
        gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
    }

    function onPromptCancel() {
        if (workNotesComplete)
            return;

    }

}

 

The issue that I am having is the popup window displays and when I add a note and hit submit, it doesn't save instead it opens another popup window.  It's like it is in a loop.

Any ideas on how I can fix this? 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

try this

function onSubmit() {

    var shortDesc = g_form.getControl('short_description');
    var longDesc = g_form.getControl('description');
    var workNotesComplete = false;
    
    if (shortDesc.changed || longDesc.changed) {

        var dialog = new GlideModal('change_confirm_reason', false, 648, 250);
        dialog.setTitle(new GwtMessage().getMessage('Cancel Change Request'));
        dialog.setPreference('focusTrap', true);
        dialog.setPreference('onPromptComplete', onPromptComplete);
        dialog.setPreference('onPromptCancel', onPromptCancel);
        dialog.on('closeconfirm', onPromptCancel);
        dialog.setPreference('buttonLabelComplete', new GwtMessage().getMessage('OK'));
        dialog.setPreference('buttonLabelCancel', new GwtMessage().getMessage('Cancel'));
        dialog.render();

        return false;

    }

    function onPromptComplete(notes) {
        workNotesComplete = true;
        g_form.setValue("work_notes", notes);
        g_form.save();
    }

    function onPromptCancel() {
        if (workNotesComplete)
            return;

    }

}

 

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I am facing the same problem. Unfortunately your script doesn't fix the infinite loop.

Regards, Darek