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 :slight_smile:

Regards,
DT

@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”}))

2 Likes

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

1 Like

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

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

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.

@bojanvelevski, I didn’t copy paste the link you provided as I have a different sftp location [which I can’t share unfortunately publicly]

Regarding account, yes, both the snaps have been mapped to the right account —> I double checked it.

Really appreciate your attention to detail, both the points were valid but it has already been taken care of!

Check if the directories are already created and the path is valid. There’s an option within the File Writer snap that allows you to create the directories/path provided, if they’re not already present.

image

Try this and let me know.

1 Like

@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.

1 Like

This is not a concern as I’m able to write files at the same location without Date.now()

Done, still not working for me.

I think it is the problem with colon in the filename which is not a valid character in many file systems generally. You could try removing that from the expression.

1 Like

Thank you @siwadon for your response but where did you find a colon ':' in the file name?

Sorry for not being more specific.

I’m not sure about the expression you are using right now. But the output of Date.now() will contain colons in the time format, 2022-04-29T19:32:29.079 UTC.

Similarly, with the expression Date.now().toLocaleDateTimeString({"format":"yyyyMMddHH:mm:ss"}), you will still get the colons in the final output. If you are using this expression, you can try removing or replacing those colons with other characters. For example, {"format":"yyyyMMddHH-mm-ss"}.

2 Likes

@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.

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"})

1 Like

This worked, THANKS A TON for your help @siwadon.

@siwadon: Why would Date.now() work without any errors while passing a parameter and generating file names dynamically vs not working for a static file name? (both of them were written via a sftp itself)

Why would Date.now() work without any errors while passing a parameter and generating file names dynamically

I doubt that it would work without removing the colons because that’s the only difference. Can you verify if the file is written successfully? If that works, what is the filename you see on the server side?

1 Like

Yes, the file was written successfully, in fact I generated ~5k html files on the sftp.

Moreover, the file name was unique, the file had 20+ columns but there was a column named ID (unique values) which was used as file name. The file name was sent as a parameter as you can see from the snap. i.e. _pipelineParameter