Does anyone have any experience with pulling files...
# suitescript
a
Does anyone have any experience with pulling files via sftp based on the lastModified value? I'm looking run a scheduled script every day that pulls the files from that day.
What I'm currently doing is pulling today's date and formatting is as "yyyy-mm-dd" and parsing the last modified date to match it. The lastmodified is formatted as "2020-08-12T170828.000Z" so I'm doing a regEx - .replace(/T.*?Z/, '') The problem is that NS is automatically formatting the lastModified as a date so it's changing the format to "Wed Aug 12 2020 100828 GMT-0700 (PDT)".
I've tried using N/format, .format to format it as text but it's still pulling up as a date. Any advice on how to fix this? Or a more direct way to go about this?
e
What does your search look like?
a
It pulls the directory list from connection.list. Here's the array that it pulls.
[{"directory":true,"name":".","size":0,"lastModified":"2020-08-12T17:08:28.000Z"},{"directory":true,"name":"..","size":0,"lastModified":"2020-08-04T18:48:03.000Z"},{"directory":false,"name":"2","size":235,"lastModified":"2020-08-12T17:08:28.000Z"},{"directory":false,"name":"2437_25945212","size":159,"lastModified":"2020-08-04T15:31:25.000Z"},{"directory":false,"name":"3","size":158,"lastModified":"2020-08-12T17:08:28.000Z"}]
e
Oh I see
Personally I'd use
moment.js
for this
I'd run a
filter
over the Array that turned
lastModified
into a
moment
and compared that to today; something like:
Copy code
let filesUpdatedToday = theFileData.filter(
  file => moment().isSame(moment(file.lastModified), "day")
)
a
Nice, definitely neater! I'm new to NS here, how would I add the Moment library to the SuiteScript library?
e
You can add third-party libs simply by uploading them to a common place in the file cabinet
I generally prefer
/SuiteScripts/lib/
or a
lib/
directory within the project
You can just upload the minified version of it and then include it like any other custom module, provided the library is AMD-compatible.
(which moment is)
a
Yup, I have a library folder which I'll upload it into. Thank you so much!