deleting attachment script from ui action not working
						
					
					
				
			
		
	
			
	
	
	
	
	
Options
			
				
					
	
			
		
	- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 04:53 AM
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
	
		
		
			
			
			
					
	
			 
					
				
		
Options
			
				
					
	
			
		
	- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 05:12 AM
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.
