Using Context variable in tMap output Column

One Star

Using Context variable in tMap output Column

Hi, I have created a Job to read CSV file, remove the double quotes and all and save to another CSV file.
tFileInputDelimited -----> tMap ----> tFileOutputDelimited

I am using two context variables.
1.File_Name
2. Name
In the tFileInputDelimited, I am setting the file name to context.File_Name.
I am mapping the source file to output file. And mapping all the columns in source to output. And it is working.
Column mapping are
row1 output
id --------------------------------------------------------------------- id
name --------------------------------------------------------------- name
city ------------------------------------------------------------------ city

Now I want to add a new column in the output file. The column header should be the context.Name value. That is if I give context.Name value to "country" , the output file should have following columns
id||name||city||country

I tried adding context.Name in the tMap. But it was showing red mark when i typed '.', means error.
So how can I achieve that?
Moderator

Re: Using Context variable in tMap output Column

Hi,
I tried adding context.Name in the tMap. But it was showing red mark when i typed '.', means error.

Is there a right output in your job. Could you paste your trouble screenshot into forum so that I can address your current situation precisely.
I have made a testing, everything is OK.
See my screenshots
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Using Context variable in tMap output Column

Oh. Not there. I know this is possible. I am asking about the column name, not the column values.
In that, you have created a column 'country'. But I want that as context.Name
So whatever value I give, the column header should be that value.
In the following image as you can see, I want to add a new column to output. Instead of newColumn, I was trying to type "context.Name" But I was not able to do.
Simply if i give "country" as value. columns should be
id||name||city||country

if i give "state" as value. columns should be
id||name||city||state

How can I achieve it?
Moderator

Re: Using Context variable in tMap output Column

Hi,
Talend don't allow to set context in schema setting or define the schema programmatically using tJava component.
Talend Enterprise Subscription Version provide "Dynamic Schema" feature which allows you to design schema with an unknown column structure (unknown name and number of columns).
TalendHelpCenter:How to process changing data structure?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Seven Stars

Re: Using Context variable in tMap output Column

You can only do it by manually creating the column headings in your output file using tFixedFlowInput. Then just append your actual rows to the same file.