- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2020 10:00 AM
Hello All, I am having difficulties removing iCalendar attachments from a Change Request.
I am aware of community post: Removing attachments using GlideSysAttachment
I may be using this wrong in a business rule.
var attach = new GlideSysAttachment();
attach.deleteAll(recordGR);
But further, can I only remove iCalendar attachments?
Solved! Go to Solution.
- Labels:
-
Change Management
- 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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2020 11:14 AM
I spoke too soon, it deletes all attachments. How can I wildcard the attachments that I wanted deleted, example "Meeting_Invitewildcard" ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2020 11:51 AM
Hi ,
Use filter condition based on content type contains calendar(your required format) and your table name and run the script:
add these lines in script:
gr.addQuery(' content_type', 'attachment format which you want to delete');
gr.setLimit(5);//test with 5 records and increase value if script works
Please mark it as helpful (or) correct if it fixes your issue
Thanks,
Sumanth
- 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