Change the "deleted attachment" message in "Ticket Attachments"

F_bio Santos
Kilo Sage

Hi everyone Im trying to change the "deleted attachment" message in "Ticket Attachments", to show which attachment got deleted, but I dont know how to get the attachment, can anyone help with this ?

F_bioSantos_0-1698052184003.png


Code:

    if (input && input.action == "deleted") {
        gr.comments = input.action + " attachment";
        gr.update();
    }

 

13 REPLIES 13

Suyog Aptikar
Giga Guru

@F_bio Santos  where are you writing this script?

'gr' is referring to which table and what is 'input' variable, can you please provide details or paste screenshot to understand better.

Essentially you need filename fro sys_attachment table hence if your 'input' hold data of attachment record that is deleted then you need to get file name in it but more details would be helpful.

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.



Best regards

Suyog

Hi  @Suyog Aptikar this script is in the "Server Script" of the wiget "Ticket Attachments".

This is the full "Server Script" of the widget:

(function() {
    data.sys_id = input.sys_id || options.record_id || $sp.getParameter("sys_id");
    data.table = input.table || options.record_table || $sp.getParameter("table");
    data.appendToId = options.appendToId;
    data.table = _getActualTable(data.table, data.sys_id);
    data.maxAttachmentSize = parseInt(gs.getProperty("com.glide.attachment.max_size", 1024));
    if (isNaN(data.maxAttachmentSize))
        data.maxAttachmentSize = 24;
    data.largeAttachmentMsg = gs.getMessage("Attached files must be smaller than {0} - please try again", "" + data.maxAttachmentSize + "MB");
    data.attachmentSuccessMsg = gs.getMessage("Attachment successfully uploaded");
    data.noDragDropMsg = gs.getMessage("Attachment drap-and-drop not enabled - use attachment button");
    data.noAttachmentsMsg = gs.getMessage("There are no attachments");

    gr2 = new GlideRecord(data.table);


	  data.estado = gr2.getValue('state');

    if (!data.table || !data.sys_id)
        return;

    var gr = new GlideRecord(data.table);
    if (!gr.isValid())
        return;

    if (!gr.get(data.sys_id))
        return;

    if (input && input.action == "deleted") {
        gr.comments = input.action + "the attachment: ";
        gr.update();
    }

    data.canWrite = gr.canWrite();
    data.canAttach = gs.hasRole(gs.getProperty("glide.attachment.role")) && GlideTableDescriptor.get(data.table).getED().getAttribute("no_attachment") != "true";
    data.canRead = gr.canRead();
    data.canDragAndDrop = gs.getProperty('glide.ui.attachment_drag_and_drop', 'true') === 'true';

    function _getActualTable(table, id) {
        if (!table)
            return table;

        var rec = new GlideRecord(table);
        if (!rec.isValid())
            return table;

        if (rec.get(id) && rec.getValue('sys_class_name')) {
            return rec.getValue('sys_class_name');
        }
        return table;
    }
})();

 

 

@F_bio Santos  thanks, what is sys_class_name here, can you print value of 'data.table'(gs.log(data.table);) and see what it is?

if table is 'sys_attachment ' you can try  gr.comments = data.file_name + "the attachment: "; and see what is coming in comment?

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.



Best regards

Suyog

Tried it @Suyog Aptikar but it returns "undefined"