[resolved] Generate a dynamic file name for tFileOutputMSXML

One Star

[resolved] Generate a dynamic file name for tFileOutputMSXML

Hi all.
I'm a newbie with Talend and I'm using a tFileOutpuMSXML to generate a XML file base on MySQL db filled from a list of files read from a folder (thanks to a tFileList).
I would like to generate a new XML file for each file found in tFileList. First I thought it will be possible to create a dynamic fileName for my MSXML output but it seem impossible (the fileName is generated at launch of th job, the solution would be to close the xml file, regenerate a new file name and reopen the file in a Java Row but I wasn't able to do it).
Is there a solution to create a new file with either a unique name for each file read by the FileList or dynamicaly set a file name for each of these files thanks to the manipulation I described but I wasn't able to do?
BR

Accepted Solutions
Highlighted
One Star

Re: [resolved] Generate a dynamic file name for tFileOutputMSXML

As it seemed that nobody had an answer about my request, I had to find another solution... and I did. Here is what I've done:

I created a tSetGlobalVar called, e.g., "myVar"
In a tJavaRow, I create a string called "myFileName" which is the dynamic part of the file name
In the same tJavaRow, I added the following code:

globalMap.put("myVar", myFileName.concat(".xml"));


I set the following file name for my tFileOutpuMSXML output: "C:/Users/cyrilp/Desktop/OutPutXML.xml"
I created a tFileCopy linked to my tFileOutputMSXML element thanks to a OnComponentOK event
I set the following parameters to my tFileCopy :
              - File name: "C:/Users/cyrilp/Desktop/OutPutXML.xml"
              - Destination folder: whatever you want
              - Rename: enabled
              - Destination file: ((String)globalMap.get("myVar"))
              - Remove source file: enabled
Then, it did the work! Smiley Happy
I don't know if it's the best way to solve a similar problem or if it would be possible to apply this on any case but it worked for me.
BR

All Replies
Highlighted
One Star

Re: [resolved] Generate a dynamic file name for tFileOutputMSXML

As it seemed that nobody had an answer about my request, I had to find another solution... and I did. Here is what I've done:

I created a tSetGlobalVar called, e.g., "myVar"
In a tJavaRow, I create a string called "myFileName" which is the dynamic part of the file name
In the same tJavaRow, I added the following code:

globalMap.put("myVar", myFileName.concat(".xml"));


I set the following file name for my tFileOutpuMSXML output: "C:/Users/cyrilp/Desktop/OutPutXML.xml"
I created a tFileCopy linked to my tFileOutputMSXML element thanks to a OnComponentOK event
I set the following parameters to my tFileCopy :
              - File name: "C:/Users/cyrilp/Desktop/OutPutXML.xml"
              - Destination folder: whatever you want
              - Rename: enabled
              - Destination file: ((String)globalMap.get("myVar"))
              - Remove source file: enabled
Then, it did the work! Smiley Happy
I don't know if it's the best way to solve a similar problem or if it would be possible to apply this on any case but it worked for me.
BR
Four Stars

Re: [resolved] Generate a dynamic file name for tFileOutputMSXML

Hi BR,
Glad that you have found the solution on your own and thanks for posting the solution.
Thanks
Vaibhav

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch