Adding Attachments in a Pop-up Modal and Saving Only When Submit is Clicked( Workspace &standard UI)

amrfahmy
Tera Contributor

Adding Attachments in a Pop-up Modal and Saving Only When Submit is Clicked

This article explains how to add attachments in a pop-up modal, with a focus on ensuring that the attachments are saved only when the Submit button is clicked. The attachments are not automatically saved during the form interaction; instead, they are stored only when the user clicks Submit or Save inside the modal. This approach provides users with control over when data is saved, allowing them to finalize the form submission and ensure attachments are included at that point.

Steps:

1. UI Page:

  • In the HTML field (lines 170-180), add the form body.

2. Client Script Field:

  • In the onSubmit function (line 786), you can handle the fields you added in the HTML field and perform any required logic.
function onsubmit(){
            // attachmentParentSysId  -> record sys_id
            // attachmentParentTable  -> table name
            // document.getElementById('field name').value;
// var ga = new GlideAjax('name')
}

3. Call Pop-up by UI Action:

For Workspace:

            g_modal.showFrame({
                url: "/attachmentForm?target_table=table_name&target_sys_id=" + g_form.getUniqueValue() +"&sysparm_workspace=true",
                title: getMessage('Title'),
                size: 's',
                height: 500,
                callback: function(ret, data) {
                    g_form.save();
                }
            });
        

For Standard UI:

            function onclick() {
                var gm = new GlideDialogWindow('attachmentForm');
                gm.setTitle('Show title');
                gm.setPreference('target_table', "table_name");
                gm.setPreference('target_sys_id', g_form.getUniqueValue());
                gm.setPreference('sysparm_workspace', 'false');
                gm.setWidth(550);
                gm.render();
            }
        

 

6 REPLIES 6

BaselT
Tera Contributor

Very helpful, thank you.

mohammedela
Mega Contributor

very helpful