- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2020 12:11 PM
I added:
gr.addQuery('text/calendar',ics);
gr.setLimit(5);
It did not work. It deleted all attachments. 1 pdf and 2 ics files, expected only the ics files to delete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2020 12:52 PM
Hi,
If you want to delete all the ics files in sys_attachment table related to your table please use below script.
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", put your table name here); // sys_id is table_sys_id
gr.addQuery("content_type", ics);// update file name as per your instance config
gr.setLimit(5);
gr.query();
while(gr.next()){
gr.deleteRecord();
}
If you want to delete only particular record attachments please use below script:
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", put your record sysid(if it is change request , copy sysid of particular change request and paste it in this line)); // sys_id is table_sys_id
gr.addQuery("content_type", ics);// update file name as per your instance config
gr.setLimit(2);
gr.query();
while(gr.next()){
gr.deleteRecord();
}
Try this and let me know
Thanks,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2020 05:58 AM
Hi ,
Are you able to fix your issue.
If it resolved your issue please mark it as correct , it will help others who are looking for similar type of solution.
Thanks,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2020 08:10 AM
Hi Sumanth, the intent is to delete all ics files from the current Change request. This will be a Business rule. Per Sanchin, this should be the correct:
gr.addQuery("table_sys_id", current.sys_id); // sys_id is table_sys_id
This is my current rule, does not work:
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.sys_id); // sys_id is table_sys_id
gr.addQuery("content_type", ics);// update file name as per your instance config
gr.setLimit(5);
gr.query();
while(gr.next()){
gr.deleteRecord();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2020 08:20 AM
This is the fix for this post:
Thank Sanchin and Sumanth for their guidance.
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.sys_id); // sys_id is table_sys_id
gr.addQuery("content_type", 'text/calendar'); // file content type is text/calendar
gr.setLimit(5);
gr.query();
while(gr.next()){
gr.deleteRecord();
}