How do I remove a text area and fix the "Save" function so data is saved properly?

yana7
Tera Contributor

How do I remove a text area and fix the "Save" function so data is saved properly?

 

yana7_0-1719222483780.png

This My UI Action

 

function onSubmit() {
    // type kode here
    if (g_scratchpad.action) {
        return true;
    }

    var gm = new GlideModal('glide_prompt', true);
    gm.setTitle('Confirmation');
    gm.setPreference('title', 'Apakah anda yakin akan menyimpan perubahan?');
    // Hilangkan text area default
    gm.setPreference('body', '');

    // Fungsi save dipanggil ketika tombol OK ditekan
    gm.setPreference('onPromptSave', save);
    gm.setPreference('onPromptCancel', cancel);
    gm.render();

    // Menambahkan HTML `<div class="modal-footer">`  untuk menempatkan tombol
    var modalFooter = document.createElement('div');
    modalFooter.classList.add('modal-footer');
    gm.getDialog().querySelector('.modal-body').appendChild(modalFooter);

    function save() {
        var data = g_form.getSubmitData();
        gsftSubmit(null, data, g_form.getActionName());
        g_form.addInfoMessage('Data berhasil disimpan');
    }

    function cancel() {
        g_form.addInfoMessage('Penyimpanan dibatalkan');
    }
    return false;
}
1 ACCEPTED SOLUTION

Amit Verma
Kilo Patron
Kilo Patron

Hi @yana7 

 

Configure the UI Action as below for your requirement :

 

AmitVerma_0-1719228438976.png

 

AmitVerma_1-1719228459301.png

 

function onSubmit() {
    var gm = new GlideModal('cancelTask');
    //Sets the dialog title
    gm.setTitle('Confirmation');
    //Set up valid custom HTML to be displayed
    gm.renderWithContent('<div style="padding:15px"><p>Apakah anda yakin akan menyimpan perubahan?</p><button style="padding:5px;margin-right:10px" onclick="window.changeTaskAction(this.innerHTML,jQuery(\'#taskCancellation\').val())" class="btn btn-default">Cancel</button><button  style="padding:5px" class="btn btn-primary" onclick="window.changeTaskAction(this.innerHTML,jQuery(\'#taskCancellation\').val())">Ok</button></div></div>');
    //We'll use the windows object to ensure our code is accessible from the modal dialog
    window.changeTaskAction = function(thisButton, thisAction) {

        //Close the glide modal dialog window
        gm.destroy();

        //Submit to the back-end
        if (thisButton == 'Ok') {
			g_form.save();
            g_form.addInfoMessage('Data berhasil disimpan');
        }
    };
    return false; //prevents the form from submitting when the dialog first loads
}

 

Output -

 

AmitVerma_2-1719228546579.png

 

AmitVerma_3-1719228661841.png

 

Please note that you can change the UI Action Name as per your requirement.

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

Amit Verma
Kilo Patron
Kilo Patron

Hi @yana7 

 

Below post could be helpful :

https://www.servicenow.com/community/now-platform-articles/custom-glide-modal-dialog-boxes/ta-p/2321...

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Amit Verma
Kilo Patron
Kilo Patron

Hi @yana7 

 

Configure the UI Action as below for your requirement :

 

AmitVerma_0-1719228438976.png

 

AmitVerma_1-1719228459301.png

 

function onSubmit() {
    var gm = new GlideModal('cancelTask');
    //Sets the dialog title
    gm.setTitle('Confirmation');
    //Set up valid custom HTML to be displayed
    gm.renderWithContent('<div style="padding:15px"><p>Apakah anda yakin akan menyimpan perubahan?</p><button style="padding:5px;margin-right:10px" onclick="window.changeTaskAction(this.innerHTML,jQuery(\'#taskCancellation\').val())" class="btn btn-default">Cancel</button><button  style="padding:5px" class="btn btn-primary" onclick="window.changeTaskAction(this.innerHTML,jQuery(\'#taskCancellation\').val())">Ok</button></div></div>');
    //We'll use the windows object to ensure our code is accessible from the modal dialog
    window.changeTaskAction = function(thisButton, thisAction) {

        //Close the glide modal dialog window
        gm.destroy();

        //Submit to the back-end
        if (thisButton == 'Ok') {
			g_form.save();
            g_form.addInfoMessage('Data berhasil disimpan');
        }
    };
    return false; //prevents the form from submitting when the dialog first loads
}

 

Output -

 

AmitVerma_2-1719228546579.png

 

AmitVerma_3-1719228661841.png

 

Please note that you can change the UI Action Name as per your requirement.

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.