Five Stars

How to pass a string correctly

Hello,

Im pretty new to Talend and now i need help in a Job im trying to make at work. All it has to do is check if there are certain Files and if not, write a specific text (or better String) to a textfile. Im using a tJava component to check for the files, creating the String (called output) and a name for the textfile it has to create (called logname). If a boolean var is set true the job has a tFileTouch that takes the "logname" and creates the File. after that a FileOutputDelimited should write the String "output" to the textfile, but it doesnt work. Ive figured out that the information of the String are lost after the "if"-connection. So im wondering how the String must be passed to reach the fileoutput at the end.Unbenannt.png

I hope that i could explain my problem properly. It would be nice if someone could help me!

 

Greetings

Jan

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: How to pass a string correctly

I'm going off what I understand from your explination.  For tSetGlobalVar, you are passing whatever you eventually need to write to the file from your tJavaRow component.  I am using fileName here, but not sure if that is what you're going to use.  I store this in the global var "outputKey" so this variable can be accessed using the code in my tFixedFlowInput  "Value" column which is then used as input to the tFileInputDelimeted.Untitled.png

Hope this helps.

4 REPLIES
Six Stars

Re: How to pass a string correctly

If the "if" connection only ever has true (i.e. it executes every time regardless of input) you don't need to have it.  You can remove that connection and take that second subjob and connect your tFileList to the tFileTouch using "OnSubjobOk". If you need to create + write to a file you can just use the tFileOutputDelimited - no need for tFileTouch too. You can hook a row connection into it to write data to a file (it will create it if it does not exist) If you need to access a variable in a different subjob.  How are you referencing the "output" variable? Are you storing it in the tSetGlobalVar? If so make sure you retrieve it in the proper way:

(String) globalMap.get("whateverYouSetTheVarAs")
Five Stars

Re: How to pass a string correctly

Hey,

thanks for the reply. Im using Filetouch because i couldnt make an "if"-connection between setglobalvar and fileoutputdelimited. And the Bool var im using for deciding if the programm needs to write the file is not always true. If everything is fine it should be false and its not necessary to write the file. So the "if"-connection was the best idea i had so far to make this job. The thing is i cannot pass the String with the information throug the "if", or at least i think that this is the problem. I hope that I understood you right... Im not used to speak english (or write). At the Moment im trying an alternative which always writes the logfile, but now im getting only nullpointerexceptions... But i think this is something different and i just forgot to set a var correctly...

Six Stars

Re: How to pass a string correctly

I'm going off what I understand from your explination.  For tSetGlobalVar, you are passing whatever you eventually need to write to the file from your tJavaRow component.  I am using fileName here, but not sure if that is what you're going to use.  I store this in the global var "outputKey" so this variable can be accessed using the code in my tFixedFlowInput  "Value" column which is then used as input to the tFileInputDelimeted.Untitled.png

Hope this helps.

Five Stars

Re: How to pass a string correctly

Wow, Thank You! It works perfect!