- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2022 01:13 AM
Hi all,
I want to delete the the attachment on data source after 10 minutes when records get created. How can we achieve it?
I am creating some records in a custom table using import set. I am attaching a CSV file on the data source.
I am trying to delete the same using post import script available on scheduled data import attached to our data source but it's not working; maybe because sys_attachment is in global and my data source is in the custom application. Please suggest what can be done.
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2022 02:22 AM
Also to note if still you are not able to delete those attachment, then would suggest to check if you are working in a Scoped Application or not?
If it is a Scoped Application then you need to enable the Can delete behavior at the Table level as shown below and allow it to delete it from other scopes as well:
Navigate to tables module and search for "Attachment" table and then go to Application Access tab as shown below and make the changes as highlighted:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2022 01:25 AM
Hello,
Please use the below script in Oncomplete transform script
var dataSourceSysId = ''; // give here the data source sys id
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'sys_data_source');
gr.addQuery('table_sys_id', dataSourceSysId);
gr.query();
gr.next();
gr.deleteMultiple();
Please mark answer correct/helpful based on Impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2022 02:02 AM
Hi, why is it necessary to delete the attachment some time after the imports have taken place?
What happens if the attachment is not deleted?
In some similar situations when working with data sources and file attachments, I have taken a different approach. I've created a Flow from inbound email, looked up the data source, deleted any attachments connected to it, and then copied files from the email which contained an updated file to be imported.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2022 02:15 AM
Hi,
Please follow the steps below to achieve your requirement:
1) You can do this from your Scheduled Job itself using the "Post Script" as shown below and use the script as shared below:
var dataSourceSysId = ''; // give here the data source sys id
var remAtc = new GlideRecord('sys_attachment');
remAtc.addQuery('table_name', 'sys_data_source');
remAtc.addQuery('table_sys_id', dataSourceSysId);
remAtc.query();
remAtc.next();
remAtc.deleteMultiple();
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2022 02:22 AM
Also to note if still you are not able to delete those attachment, then would suggest to check if you are working in a Scoped Application or not?
If it is a Scoped Application then you need to enable the Can delete behavior at the Table level as shown below and allow it to delete it from other scopes as well:
Navigate to tables module and search for "Attachment" table and then go to Application Access tab as shown below and make the changes as highlighted:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke