One Star

tFileOutput dynamically filename

Hello everyone,
i am stuck within a simple? problem.
If have a small process to extract data from a big xml file and save the output it in several small files.
the filename of each output file is dependent of the actual data.
example inputfile:
<PLANT>
<COMMON>Bloodroot</COMMON>
</PLANT>
<PLANT>
<COMMON>Columbine</COMMON>
</PLANT>
output files:
bloodroot.xml
columbine.xml
I extract the 'common' property into the context variable : context.FILENAME
But at execution time i only get one file: null.xml
How can i dynamically set the filename of the tfileoutput component?
Thanks your help
Michael
4 REPLIES
One Star

Re: tFileOutput dynamically filename

Does nobody have a tip or workaround for that?
One Star

Re: tFileOutput dynamically filename

You are using correct file name but I think context variable are not initialized with proper values
You are using two context variables context.OUTPUTPATH, context.FILENAME
Try displaying data contained in 'common' property and context variables
Also select check box Append in tFileOutputDelimited so exisiting files are appended
Seven Stars

Re: tFileOutput dynamically filename

The output file is initialised before the flow starts i.e. before the input file is even opened so you can't use values from the input for the output file name. There are other posts about how to achieve this e.g. http://www.talendforge.org/forum/viewtopic.php?id=12493.
One Star

Re: tFileOutput dynamically filename

The output file is initialised before the flow starts i.e. before the input file is even opened so you can't use values from the input for the output file name.

Thats correct!
I used this approach:
Write the data to tempfiles and at the end rename your files to the appropiate name.