- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2023 12:32 PM
Hello experts, please I need your help, I need to create a scheduled job that will delete all attachments except the content type that is not an image.
I got this from another post:
tested it with a single incident, used the sys_id from the incident and worked.
this is how I tested it:
But I need to include in the script the condition to remove all types of attachments except the ones that include images and that were created 7 days ago.
how can I insert this condition?
Thank you
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2023 01:12 PM - edited ‎03-23-2023 01:51 PM
Hi jesus,
You can try this in your Scheduled script
var gr = new GlideRecord('sys_attachment');
gr.addEncodedQuery('table_nameLIKEincident^content_typeNOT LIKEimage^sys_created_onRELATIVEGT@dayofweek@ago@7');
gr.query();
gr.deleteMultiple();
Mark Correct and Helpful if it helps.
***Mark Correct or Helpful if it helps.***

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2023 01:12 PM - edited ‎03-23-2023 01:51 PM
Hi jesus,
You can try this in your Scheduled script
var gr = new GlideRecord('sys_attachment');
gr.addEncodedQuery('table_nameLIKEincident^content_typeNOT LIKEimage^sys_created_onRELATIVEGT@dayofweek@ago@7');
gr.query();
gr.deleteMultiple();
Mark Correct and Helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2023 01:50 PM
Thank you Yousaf it worked this way!
Regards

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2023 02:03 PM
Sure No Problem.
Glad! it worked
***Mark Correct or Helpful if it helps.***