- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 04:06 AM
I want to import a data set from SFTP on a daily basis where the file name changes daily like fileddmmyy.csv.
Any recommendation to achieve this ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 04:39 AM
Hi,
you need to update the file name in the data source just before the sftp job runs
Use schedule job which runs just 5-10mins prior to the scheduled data import for this sftp
sample script below
Note: ensure you give valid data source sys_id
valid file path
the below code will help you give file name daily as file061820.csv, file061920.csv
ensure you use valid file path
var gr = new GlideRecord('sys_data_source');
gr.addQuery('sys_id',''); // give here the data source sys_id
gr.query();
if(gr.next()){
var gdt = new GlideDateTime();
var dateTime = gdt.toString();
var arr = dateTime.split(' ');
var yearDate = arr[0].split('-');
var dd = yearDate[1];
var mm = yearDate[2];
var year = yearDate[0];
var yearPart = year.substring(0,2);
var str = 'file' + dd + mm + yearPart + '.csv';
gr.file_path = str;
gr.update();
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2020 04:39 AM
Hi,
you need to update the file name in the data source just before the sftp job runs
Use schedule job which runs just 5-10mins prior to the scheduled data import for this sftp
sample script below
Note: ensure you give valid data source sys_id
valid file path
the below code will help you give file name daily as file061820.csv, file061920.csv
ensure you use valid file path
var gr = new GlideRecord('sys_data_source');
gr.addQuery('sys_id',''); // give here the data source sys_id
gr.query();
if(gr.next()){
var gdt = new GlideDateTime();
var dateTime = gdt.toString();
var arr = dateTime.split(' ');
var yearDate = arr[0].split('-');
var dd = yearDate[1];
var mm = yearDate[2];
var year = yearDate[0];
var yearPart = year.substring(0,2);
var str = 'file' + dd + mm + yearPart + '.csv';
gr.file_path = str;
gr.update();
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 06:52 AM
Hi @Ankur Bawiskar ,
I tried this same code on my instance and for some reason the scheduled job is not updating de data source file path. When I execute now the schedueled job nothing happens.
Can you please help me understand what's going on? Thank you a lot!