delete attachment from data source 10 minutes after creating records

Nitin26
Tera Contributor

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

1 ACCEPTED SOLUTION

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:

find_real_file.png

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

6 REPLIES 6

Saurav11
Kilo Patron
Kilo Patron

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

OlaN
Giga Sage
Giga Sage

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.

shloke04
Kilo Patron

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();

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

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:

find_real_file.png

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke