Four Stars

Setting "Dynamic Column Value" using tJavaRow

Hi,

 

I used the following code suggested in Talend documentation to retrieve a dynamic field value using tJavaRow.

 

Dynamic columns = row3.other;

for (int i = 0; i < columns.getColumnCount(); i++) {  
      DynamicMetadata columnMetadata = columns.getColumnMetadata(i);  
      System.out.println("Column Name = " + columnMetadata.getName());

      System.out.println("Column Value = " + columns.getColumnValue(i));
}

 

In my case the column value is of type String. I want to replace the newline in the column value with a space.

I can use replace function in java. But to put the replaced string back to the Dynamic field is where I get lost.

is there any method that I can use put the string back to dynamic field? something like "setColumnValue"?

 

Also I couldn't find documentation for Dynamic and DynamicMetadata (routines.system.Dynamic and routines.system.DynamicMetadata). Can someone share the documentation link if they have please?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Ten Stars

Re: Setting "Dynamic Column Value" using tJavaRow

first: are you using dynamic column type.
if you know your column you do not need it.

If you are using it:
Dynamic columns = row3.other;

for (int i = 0; i < columns.getColumnCount(); i++) { 
      DynamicMetadata columnMetadata = columns.getColumnMetadata(i); 
      if (columnMetadata.getName().equals("yourColName"))
           {columns.setColumnValue(i,columns.getColumnValue(i).replace("newline"," "))};
}

 

Francois Denis

Don't forget to tag when it's "solved"!

2 REPLIES
Ten Stars

Re: Setting "Dynamic Column Value" using tJavaRow

first: are you using dynamic column type.
if you know your column you do not need it.

If you are using it:
Dynamic columns = row3.other;

for (int i = 0; i < columns.getColumnCount(); i++) { 
      DynamicMetadata columnMetadata = columns.getColumnMetadata(i); 
      if (columnMetadata.getName().equals("yourColName"))
           {columns.setColumnValue(i,columns.getColumnValue(i).replace("newline"," "))};
}

 

Francois Denis

Don't forget to tag when it's "solved"!

Four Stars

Re: Setting "Dynamic Column Value" using tJavaRow

Hi,

 

Thanks for your reply. This works fine. I can now set the column value using setColumnValue(int, str).

 

Regards,

Ramya