Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

deleting attachment script from ui action not working

jobin1
Tera Expert

Hi All

tried below script in ui action to delete sys_attachment records but not working i am getting alert correctly. 

 
var sysidvalue =g_form.getUniqueValue();
alert("sysidvalueis"+sysidvalue);  //getting alert
 var attachmentGR = new GlideRecord('sys_attachment');
    attachmentGR.addQuery('table_name', 'u_email_client');
attachmentGR.addQuery('table_sys_id', sysidvalue);
attachmentGR.addQuery('content_type', 'STARTSWITH', 'image/');
    attachmentGR.query();
 
    while (attachmentGR.next()) {
        attachmentGR.deleteRecord();
alert("whilending"); //getting alert
    }
}
//updated by jobin for deleting sys attachment when swiching to view text ends

 

1 REPLY 1

Marcos Kassak
Kilo Sage

Hi @jobin1,

 

When you navigate into the sys_attachment table and make this very same query that you did on code, but on filter - does it return the records that you want to delete? Also, try another way of debugging:

 

    var sysidvalue = g_form.getUniqueValue();
    alert("sysidvalue is " + sysidvalue); // Ensure sysidvalue is being fetched correctly

    var attachmentGR = new GlideRecord('sys_attachment');
    attachmentGR.addQuery('table_name', 'u_email_client');
    attachmentGR.addQuery('table_sys_id', sysidvalue);
    attachmentGR.addQuery('content_type', 'STARTSWITH', 'image/');
    attachmentGR.query();

    while (attachmentGR.next()) {
        attachmentGR.deleteRecord();
        gs.addInfoMessage("Deleted attachment: " + attachmentGR.getDisplayValue()); // Display message for each deleted attachment
    }

 

Let me know the results.