How to delete attachment from a Data Source which is associated with a Scheduled Data Load?

amala2
Mega Guru

We have a data source where we manually attach an attachment.This Data Source is associated with a 15 minute periodically executing Scheduled Data Import.The attachment is related to sys_user table.After the attachment upload[after the scheduled data import execution],If I manually change any user record data ,the data source attachment overrides the value as the Scheduled data import runs again after 15 mins.

Is there a way to delete an attachment once its executed by the scheduled data import?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Amala,

you can have following script in the post execute script which would run once the transform runs so that older attachment is deleted and new one can be attached.

you need to set the checkbox of execute post-import script

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

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Amala,

you can have following script in the post execute script which would run once the transform runs so that older attachment is deleted and new one can be attached.

you need to set the checkbox of execute post-import script

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

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader