The CreatorCon Call for Content is officially open! Get started here.

HugoFirst
Kilo Sage

Recently, we had a requirement to create a pop-up to confirm an update to a record.  As part of the confirmation, the user had to enter the exact text "Proceed".  This article presents the approach we used which involves only one client script and the OOB modal object. Feel free to offer improvements.

I developed the client script after referring to 2 articles:
 https://davidmac.pro/posts/2022-02-08-glidemodal/
& https://gist.github.com/icerge/4c29728c4a8cf0c04ef8bc8cf14519c1

Here is what the modal popup looks like: find_real_file.png

I present the code below followed by commentary which describes the flow of the script when it is used.

function onSubmit() {

    if (g_scratchpad._action_confirmed) {
        return true;
    }

    var gm = new GlideModal("glide_prompt", true, 600);
    gm.setTitle("Confirm Update");
    gm.setPreference("title", "Please enter 'Proceed' and click OK if you want to update this record.");
    gm.setPreference("onPromptComplete", doComplete);
    gm.setPreference("onPromptCancel", doCancel);
    gm.render();

    function doComplete(value) {
        var msg = ' wrong text entered.   Update Aborted. text=' + value;
        if (value == 'Proceed') {
            g_scratchpad._action_confirmed = true;
            msg = 'You entered Proceed.  Update permitted.';
            gsftSubmit(null, g_form.getFormElement(), g_form.getActionName());
        }
        alert(msg);
    }

    function doCancel(value) {
        alert("in doCancel.  Update is aborted.  value = " + value);
    }
    return false;
}

This client script runs when the form is submitted.   A quick overview of the form's execution will explain it's confusing logic.

1. The script is called when the record is updated.  g_scratchpad.action_confirmed is not set to true so the logic falls thru the first if statement.

2. The GlideModal object is defined and rendered.  

3. The client script returns false ( which disallows the update )

4. But it's not over yet!   The modal popup is displayed and the user will enter text ( or not ) and click a button  ( Cancel or OK ).

5. If the user clicked Cancel, then the alert is presented and the record is still not updated.

6. if the user clicked OK, then the text that was entered is checked against the expected value.  It the value matches, g_scratchpad.action_confirmed is set to true and the form is resubmitted.  When this client script is executed for the second time,  the initial IF clause is invoked and the return value is "true".  This allows the update to proceed.

Comments
Ch Saipriya
Tera Explorer

Is there any way to increase the prompt/text box area?

CezaryBasta
Tera Guru

@Ch Saipriya sure. In the GlideModal constructor you provide a UI Page to render. You may as well create your own (also based on one of the OOB ones) and customise its CSS.

Version history
Last update:
‎08-01-2022 02:16 PM
Updated by: