Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

@F_bio Santos  sorry, I am not well versed with portal, I would leave other experts to probably have a look here.

I will try to explore at my end as well and would let you know if I have any findings.

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



Best regards

Suyog

ok, ok @Suyog Aptikar thank you  šŸ˜€

Ankur Bawiskar
Tera Patron
Tera Patron

@F_bio Santos 

update as this to know the file name, see if this works for you

(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");

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") {

var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', data.sys_id);
att.query();
if(att.next()){
gs.addInfoMessage("Attachment " + att.file_name + " is deleted");
}

gr.comments = input.action + " an 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;
}
})();

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar for some reason it is only running the:

        gr.comments = input.action + " the attachment: "  ;
        gr.update();


It is not running the :

if(att.next()){
gs.addInfoMessage("Attachment " + att.file_name + " is deleted");
}



@F_bio Santos can you replace gr.comments = input.action + " an attachment"; with 

gr.comments ="Attachment " + att.file_name + " is deleted"; 

 and see if this helps

something as below:

if (input && input.action == "deleted") {

var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', data.sys_id);
att.query();
if(att.next()){
gs.addInfoMessage("Attachment " + att.file_name + " is deleted");
gr.comments = "Attachment " + att.file_name + " is deleted";
}
gr.update();
}

 

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



Best regards

Suyog