Employee

Flow to String

I came across this interesting problem. I did find a solution, but I somehow feel it could be more elegant.
I have a job that produces a number of records, and I would like to send an e-mail containing all these records (maybe just some fields of them). That is, I want to send a single e-mail for all the records, not individual e-mails for each.
So I guess my problem is to gobble up an entire Talend flow into a string and then use that string as part of the e-mail message in tSendEmail. But how do I turn an entire flow into a string? I solved it using a tJavaRow and the globalMap, but it doesn't seem very elegant to me.
Maybe I'm missing something entirely different? Comments appreciated.
Andre
2 REPLIES
One Star

Re: Flow to String

I agree it's bad to use globalMap in each row. But standard component tAggregateRow can only give you a comma separated list: "str1,str2,str3..."
I would use local var that can be defined in either begin part of tJavaFlex like this:
(subjob)--row19-->tJavaFlex
or in tJava like this:
tJava--iterate-->(subjob) .
After that either use tAggregateRow with dummy group (it will produce 1 row) or put the var to globalMap and read it in another subjob connected with onSubjobOK
Six Stars

Re: Flow to String

Yeah this is a common need that I think that usually requires too much effort for the task...
a quick solution could be to attach a TXT file produced by tfileout fixed components for the records in the email and then attach such file in the email message, but of course you haven't much control on the final layout if a user need to consume it.
Or you can use a full reporting solution (ie tjasper components) to produce such TXT file.
Another solution requiring little modification to tsendmail component as a feature request is to allow to fetch the body from a produced TXT file ( so the user doesn't need to go for the attachment, instead the whole information is in the mail body ).
Another good thing would be to integrate some very good templating system to talend, like Freemarker, to quickly produce good final text files from records (it will fits talend row based model nicely)... such template system could be used also for other purposes like generating sql query string etc...