Forum Discussion

darshthakkar's avatar
darshthakkar
Valued Contributor
4 years ago
Solved

Using Date.now() while exporting files

Hi Team,

While writing files via sftp, I’m unable to ingest Date.now() in the filename itself as seen in the snaps below:

(1) Successful execution [passing pipeline parameter and selecting the ‘=’ decorator

(2) Failed execution [NEITHER passing any parameter NOR selecting ‘=’ decorator]

The reason behind not selecting = decorator is - “I’m not passing any parameter to dynamically generate filename”
If the file name needs to be constant and it needs to be exported via sftp with Date.now(), what tweaks should I do? I’m pretty sure, snapLogic would be able to handle that and I might be doing something wrong here.

Thanks in advance for your help 🙂

Regards,
DT

21 Replies

  • Supratim's avatar
    Supratim
    Contributor III

    @darshthakkar Make expression enabled by clicking on the “=” on filename and can use below expression - “%s/%s%s.csv”.sprintf(“baseSFTPPath”,“constantFileName”,Date.now().toLocaleDateTimeString({“format”:“yyyyMMddHH:mm:ss”}))

    • darshthakkar's avatar
      darshthakkar
      Valued Contributor

      Thank you @Supratim for providing the string for file writer but this is failing as well.

      • Supratim's avatar
        Supratim
        Contributor III

        @darshthakkar Just to make sure you config correctly - 1. use wincsp/other tools to login the sftp server (please use same credential as used in snaplogic). And try to create a file there. If you can then it should work in snap as well.
        2. Make sure you choose cloudplex/groundplex correctly.
        3. And hope you validate this is sftp server not smb.

  • bojanvelevski's avatar
    bojanvelevski
    Valued Contributor

    Hey @darshthakkar,

    Turn on the expressions support, and wrap the static part of the path in quotes. Than simply add the Date.now() function at the end. It will look something like this:

    "sftp://localnetwork:22/usr/local/Enterprise/server/sharedcommon/incoming/SCM/Users/DT/inbound/ErrorLog.xlsx" + Date.now()

    But I suppose you want the Date first, than the file extension so I would go with this:

    "sftp://localnetwork:22/usr/local/Enterprise/server/sharedcommon/incoming/SCM/Users/DT/inbound/ErrorLog_" + Date.now() + ".xlsx"

    Regards,
    Bojan

    • darshthakkar's avatar
      darshthakkar
      Valued Contributor

      Thanks @bojanvelevski for providing the actual string however it is failing as seen in the below snap:

      • bojanvelevski's avatar
        bojanvelevski
        Valued Contributor

        First, check the spelling, I wrote the expression from the image you provided, so I may have missed something.

        Also, I noticed that you’re using 2 different snaps in your samples above, so check if the Account is properly configured.

  • darshthakkar's avatar
    darshthakkar
    Valued Contributor

    @siwadon: Thanks for the clarification, I’ve replied to my previous comment so that you can check the screenshot of a successful run.

    Date.now() works well if I’m passing a parameter for writing my files however if I provide a static name to a file (e.g. TestFile) and want to ingest Date.now(), it doesn’t work.

    Again, Date.now() to a static file name would work if the files are written in snapLogic Manager however I faced the challenge while writing the files to a sftp.

    Let me know if you need any further clarifications and I would be more than happy to provide you all the details.

    • siwadon's avatar
      siwadon
      Employee

      Understood but I don’t think it’s the problem with the static or dynamic reference if you can write other files to the FTP server without any problems. The only thing I could think of is that the filename contains illegal characters.

      Can you please try the expression below first?

      Date.now().toLocaleDateTimeString({"format":"yyyyMMddHHmmss"})

  • khanh_tran's avatar
    khanh_tran
    New Contributor III

    Woah. That’s great. I didn’t know that. You’re my hero. hahaha. Here is my result. I worked.