The CreatorCon Call for Content is officially open! Get started here.

Dynamically Update file path in SFTP Data Source with a changing filename

bhaskarnataraju
Tera Contributor

Can we fetch file name from SFTP server and replace the path of data source?

As of now i am able to replace path using script(mentioned below) in Scheduled Import Per-script. Kindly let me know if i will be able to fetch file name from SFTP server using script.

var path =("/StaticName.csv");
var grd = new GlideRecord('sys_data_source');
grd.addQuery('sys_id', '2hcage521b6g63c0c0df29877e4bcbfa');
grd.query();
while(grd.next()){
grd.file_path = path;
grd.update();
gs.log(path);
}

 

1 ACCEPTED SOLUTION

Hi Bhaskar,

if naming convention is not followed then you can't fetch the file from that sftp folder although single file exists in that folder at the time of fetching, ServiceNow would require exact file name to be fetched from sftp folder location.

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

5 REPLIES 5

Hi @Ankur Bawiskar ,

 

How can we fetch the exact file name if naming convention is followed using schedule job

var path =("/StaticName.csv");

var filename = "filename.xlsx"
var grd = new GlideRecord('sys_data_source');
grd.addQuery('sys_id', '2hcage521b6g63c0c0df29877e4bcbfa');
grd.query();
while(grd.next()){
grd.file_path = path;
grd.update();
gs.log(path);
}