Send query result by mail

Highlighted
Seven Stars

Send query result by mail

Using what is described in following link:

https://community.talend.com/t5/Design-and-Development/resolved-Sending-query-result-by-mail/m-p/100...

 

I am able to send the query results by email but the email is print results column after column and not in row.

By that I mean if my table looks like this:

 

Name   Date

John     05-08-2019

Nas      05-07-2019

 

The email that I get is this:

Name:

John

Nas

Date:

05-08-2019

05-07-2019

 

This is what I have in tjavarow:

context.StepName = context.Name+"\n"+input_row.Name;
context.Timestamp = context.Timestamp+"\n"+input_row.Timestamp;

 

And this is how the email message in tsendMail is composed:

"Name: "+context.StepName+ " Date:" + context.Timestamp+"."

 

What I would like to see in the result is each row with column header:

 

Name   Date

John     05-08-2019

Nas      05-07-2019

 

How can I accomplish this?

talend_mail.PNG

Thanks

Tags (1)

Accepted Solutions
Employee

Re: Send query result by mail

Hi,

 

    Your email component is called after tjavarow data processing using on SubJob Ok.

 

So the context.StepName is havig data as below

 

Name:
John
Nas

   since you have given the code as shown below. It means, the data of name will get continously accumulated to the StepName column one after another.

   context.StepName = context.Name+"\n"+input_row.Name;

 

   Instead of this, you can do a simple trick.

 

Assign the initial value of context.Step as shown below.

 

context.Step="Name"+"\t"+"Date";

Inside tjavarow, add as below.

 

context.Step= context.Step+"\n"+input_row.Name+"\t"+input_row.Timestamp;

Then, use the context.Step inside your existing tSendmail (which is connected using OnSubJobOk). This should reslve your issue :-)

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

 

 

 

 

    

View solution in original post


All Replies
Employee

Re: Send query result by mail

Hi,

 

    Your email component is called after tjavarow data processing using on SubJob Ok.

 

So the context.StepName is havig data as below

 

Name:
John
Nas

   since you have given the code as shown below. It means, the data of name will get continously accumulated to the StepName column one after another.

   context.StepName = context.Name+"\n"+input_row.Name;

 

   Instead of this, you can do a simple trick.

 

Assign the initial value of context.Step as shown below.

 

context.Step="Name"+"\t"+"Date";

Inside tjavarow, add as below.

 

context.Step= context.Step+"\n"+input_row.Name+"\t"+input_row.Timestamp;

Then, use the context.Step inside your existing tSendmail (which is connected using OnSubJobOk). This should reslve your issue :-)

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

 

 

 

 

    

View solution in original post

Highlighted
Seven Stars

Re: Send query result by mail

That worked.

 

Thanks for your help.

Highlighted
Four Stars

Re: Send query result by mail

Hi nikhilthampi,

I followed your explanation for that post, but got slighlty differnt results than wanted.

instead of geting all query results in the mail i only get the last row.

I guess tjava overright the context var each time, but dont know how to fix that.

 

This is the Log before Javarow:

Capture.JPG

JavaRow:

context.header="player_id"+"\t"+"Alert"+"\t"+"timecreated";
context.output=context.header+"\n"+input_row.player_id+"\t"+input_row.Alert+"\t"+input_row.timecreated;

tSendMail:

context.output

and that is what i get in mail:

Capture2.JPGonly 1 line

 

 

this is the full Job:

Capture3.JPG

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog