Five Stars

Rename an output file with the name of a variable (dinamic) and the current date

Dear all,

i need to rename an output (csv) file based on a variable that is inside the Job + the current date. An exemple of the output can be "markertId-ddmmyyyy" where markertId is the variable and ddmmyyyy is the date of the day.

 

Thanks for the help

2 ACCEPTED SOLUTIONS

Accepted Solutions
Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

Replace the 1rst tFixedFlowInput by your tFileInputExcel.

For the 2nd tFixedFlowInput, you just have to define the schema depending on what you expect in the target output file then populate each field with the global variable defined by the tFlowToIterate as in the example I proposed.

Import the job I've attached to a previous answer and play with it, this is the best way to learn.

 

Also, don't forget to accept the solution as it solved your case (Kudo also accepted).


TRF
Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

You should trace the content after tFileInputExcel and before tFileOutputDelimited to verify the flow content (tab Debug Exec then Trace Debug).


TRF
22 REPLIES
Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

((String)globalMap.get("markertId")) + "-" + TalendDate.formatDate("ddMMyyyy", TalendDate.getCurrentDate())

TRF
Five Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

Thanks for the answer, unfortunately that is the error message that talend displays me (see the attached file)

 

Eleven Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

is this you are looking for ?Untitled.png

Manohar B
Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

@samfantini please share your tFileOutputDelimited settings for the compilation error.

You were talking about "a variable that is inside the Job".

I thought you were talking about a global variable.

If this is not exact, can you clarify this point?

Are you talking about a global variable, a context variable or a field?


TRF
Five Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

Sorry, I was talking about a field within the Job that takes on value. I would like to put that value in the name of the output csv file followed by the date of the day.

in the 2 pictures below i have highlighted in yellow the name of the field and in the other the settings of the toutputdelimited.

the problem for me is what i have to write in the file name field in the outputCattura1.PNGCattura3.PNG

Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

So you have to iterate over the content to write into the appropriate output file.

The job design should look like this:

Capture.PNG

tFixedFlowInput is here for the example - it replaces your tFileInputDelimited.

It content is here (just 3 fields for the example):

Capture.PNG

tFlowToIterate generates 1 global variable per input field (3 in my case).

Just let it with the default options.

tFixedFlowInput generates a flow from the global variables generated at the previous step.

Capture.PNG

As you can see, each field is completed with the associated global variable.

Then the flow is pushed into the tFileOutputDelimited.

The filename is like this:

"C:/Users/safantin/Desktop/" + 
(String)globalMap.get("row79.marketId") + "-" +
TalendDate.formatDate("ddMMyyyy", TalendDate.getCurrentDate()) + ".csv"

Just beware of the "" around each fixed part.

Tick the option "Write after" on the Advanded Settings tab of the tFileOutputDelimited in case of many records with the same value for the marketId field.

That's all.


TRF
Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

@samfantini, just try it


TRF
Five Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

Perfect, but i don't understand the "inline table", because i have many records in my table.

my records seems like this:

 Cattura.PNG

but i have too many records.

so i would like to know how the second tFixedFlowInput works.

Seven Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

Hi samfantini,

 

As per your comment, are you getting the "markertId" from input data or from any variables like context/global.

Please provide your inputs on this.

 

Thanks,

Bharath.

Five Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

I get the field "markertId" from the input file Excel. 

Seven Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

In that case you will get number of output files is equal to number of "markertId" from input.

 

Ex : "markertId" count is 3 then you will get 3 output files.

 

Is this is the output you expected?

Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

Replace the 1rst tFixedFlowInput by your tFileInputExcel.

For the 2nd tFixedFlowInput, you just have to define the schema depending on what you expect in the target output file then populate each field with the global variable defined by the tFlowToIterate as in the example I proposed.

Import the job I've attached to a previous answer and play with it, this is the best way to learn.

 

Also, don't forget to accept the solution as it solved your case (Kudo also accepted).


TRF
Five Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

@javvaji Yes, that is what i expect. i have 3 (or more) different values and i would like to have 3 (or more) different files named like the values of the field markertId

Seven Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

Then you need to use tFlowtoIterate component and need to iterate each value from input and should use the tFlowtoIterate global property and need to use it in output filename column in tFileOutputDelimited component.

Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

@javvaji you should read previous replies...


TRF
Seven Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

@TRF ya i know you have given answer, but still he asked right so i gave reply.

Five Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

("row79.marketId")

Why do you have used row79.marketId?? because now the file have the date, but does not have the name of the field.

 

Cattura.PNG 

Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

You have to change "row79" by your own "row name" depending on what it is in your job.


TRF
Five Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

1)but, as you can see in the screen, there are no values but only the names of the fields. How i can import the values of the table?

2) i would like to replace row79 with the correct field but i don't find the correct field. where is it?

what setting i have to use? : - values

                                             - inline table 

                                             - inline content?
Cattura.PNG

Seven Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

For the values you need to use ctrl+space then you will able to see the properties of tFlowToIterate_1 component and there you will find the property name with the column name  as input column name.

 

Ex : ((String)globalMap.get("row1.dateTime"))

Five Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

ok. now the name of the output file is correct, the problem is that the 3 files generated are without records. And i think the problem is that i dont know how i can retrieve the values of the fields

Thirteen Stars TRF
Thirteen Stars

Re: Rename an output file with the name of a variable (dinamic) and the current date

You should trace the content after tFileInputExcel and before tFileOutputDelimited to verify the flow content (tab Debug Exec then Trace Debug).


TRF