Filename context

Seven Stars

Filename context

Hello everyone,

 

I'm trying to get a file from FTP which is composed of a date looking like : yyyyMMdd_hhmm (exemple : *TEXT*_20180509_1030.xml) and then turn it to CSV.

Since there will be file everyday, i planned to add a context variable and use it in the file name.

 

 aaa.png

  

Here is what it looks like : 

 

New context : "FTP_GET " 

value :  "TEXT"+TalendDate.formatDate("yyyyMMdd_hhmm",TalendDate.getCurrentDate())+".xml" 

 

My FTPGET is working fine, tho, my TFileInputXML doesnt understand my path, what i'm missing?

FileName : "C:/Users/......../"+context.FTP_GET.

 

Another question, must I write the file from FTP GET on my disk and then get it back with my tFileInputXML ? Can't i keep the data on Talend and not write then on my disk?


Thanks for the answer!

 


Accepted Solutions
Sixteen Stars

Re: Filename context

This is easily fixed. Your problem is caused by trying to use Java to set the context variable in your Contexts tab. You cannot do this. If you want to set a Context variable using code, you can add a tJava component before your tFileList, connect it via an OnSubJobOK link and add this code to it....

 

context.FTP_GET = "Text"+TalendDate.formatDate("yyyyMMdd_hhmm",TalendDate.getCurrentDate())+".xml";

This MUST be done in a prior subjob to the subjob you are going to use it for a filename

 

 


All Replies
Forteen Stars TRF
Forteen Stars

Re: Filename context

For sure, your tFileInputXML must contain the full pathname for your XML file (including directory).

For the 2nd question, no can't. You must get the file locally, then you can read it using tFileInputXML except if the file is stored on a shared drive (probably not if you use ftp).


TRF
Seven Stars

Re: Filename context

Hi @TRF and thanks for the reply !

 

Thanks for the second answer. About the first one, I don't get it. My tFileInputXML does contain my fullpathname, its just that it doesnt use my context result and returning it as an error (syntax incorrect, see screenshot). I must do something wrong when i use context in the settings ?

 

context : FTP_GET , value : "Text"+TalendDate.formatDate("yyyyMMdd_hhmm",TalendDate.getCurrentDate())+".xml"

 

Filename : " C:/"+context.FTP_GET "

 

Forteen Stars TRF
Forteen Stars

Re: Filename context

Can you share your tFTPGet settings and the piece of code where you set the context variable value.


TRF
Sixteen Stars

Re: Filename context

This is easily fixed. Your problem is caused by trying to use Java to set the context variable in your Contexts tab. You cannot do this. If you want to set a Context variable using code, you can add a tJava component before your tFileList, connect it via an OnSubJobOK link and add this code to it....

 

context.FTP_GET = "Text"+TalendDate.formatDate("yyyyMMdd_hhmm",TalendDate.getCurrentDate())+".xml";

This MUST be done in a prior subjob to the subjob you are going to use it for a filename

 

 

Sixteen Stars

Re: Filename context

I just read the other part of your question. You can stream the file data from its source location, but it is  trickier. You will need to the tFileFetch (https://help.talend.com/reader/9q55KsfASqX0qY4GVhEDNQ/pfuQtcwLBNAvHnxMDbe2ag) and make use of the "Use cache to save resource" make.

 

This tutorial might help (https://help.talend.com/reader/iYcvdknuprDzYycT3WRU8w/2kKyGJVxys~Zwh8HsNLtaQ) 

Seven Stars

Re: Filename context

Thanks for the reponse to both of you, @rhall_2_0 , @TRF

 

I had already tried the tJava component via OnsubJob Ok tho, I still have the same error where my tFileInputXML is not interpreting my context value.

 

aaa.png

 

As you can see it looks like he doesnt get the TalendDate fonction and use it as a string. (Basically : syntax wrong)inputxml.png

 

 

Sixteen Stars

Re: Filename context

You are not showing enough info. If you tried my solution, it WILL have worked. So can you show me precisely how you tried it (hiding nothing.....there are no spies here trying to work out information about you or your organisation via filepaths) please?

Seven Stars

Re: Filename context

Edditing my response here, I tried to change some stuff & finally worked by linking the tJava to the tFileInputXML instead of tFTPGet ... No idea why but yet its working, resolved then, thanks for the tJava tricks Smiley Happy.

Kindly