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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Bhaskar,

So currently you are able to fetch the file from sftp by dynamically changing the file name in the file path column?

what is your exact question?

Regards

Ankur

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

Hi Ankur,

 

Thanks for quick response.

I am able to fetch file from SFTP server and load it in ServiceNow if the file name is known. SFTP server is hosted in client place and client will not follow standard naming convention and it might be anything. Kindly let me know how to fetch file name from SMTP server so that i can update path in data source and process correct file.

 

Note: there will be only one file in folder. once data is processed, we are moving the file to other location using script.

 

Kindly let me know if you need additional info.

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

Thanks Ankur. I have requested client to follow standard naming convention based on your feedback.