Using tSendMail with tJavaRow

Five Stars

Using tSendMail with tJavaRow

Dears,

I am trying to get data from MySQL and eventually send it as html email messsage.

I read many articles here but dont understand issue with my flow. 

I am getting results, but email content dont show "FirstName" while email sending is fine.

In context option i added one string as "Fname" and in my table i have one "FirstName" column.

in tJavaRow components i added this code : 

context.FName= input_row.FirstName;

And then in tSendMail message added : 

context.FName

Screenshot_1.jpg

 

Please advise what i am doing wrong. Thanks


Accepted Solutions
Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

Here is my tJavaRow (with correction on html syntax):

 

String msg = ((String)globalMap.getOrDefault("mailMsg", "<table><tr><th>ID</th><th>FirstName</th><th>LastName</th></tr>"));
msg = msg +
"<tr>" +
"<td>" + input_row.Id + "</td>" +
"<td>" + input_row.FirstName + "</td>" +
"<td>" + input_row.LastName + "</td>" +
"</tr>";

globalMap.put("mailMsg", msg);

and here is what tJava print on the console:

 

 

[statistics] connecting to socket on port 3767
[statistics] connected
.--+---------+--------.
| tLogRow_40 |
|=-+---------+-------=|
|Id|FirstName|LastName|
|=-+---------+-------=|
|1 |AAA |BBB |
|2 |ABC |DEF |
|3 |DEF |GHI |
'--+---------+--------'

<table><tr><th>ID</th><th>FirstName</th><th>LastName</th></tr><tr><td>1</td><td>AAA</td><td>BBB</td></tr><tr><td>2</td><td>ABC</td><td>DEF</td></tr><tr><td>3</td><td>DEF</td><td>GHI</td></tr>
[statistics] disconnected

Do you have synchrnized your tJavaRow schema?

 

If not, do it and retry.


TRF

All Replies
Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

If you want to send 1 email per record, you need to add a tFlowToIterate after the tJavaRow component then connect it to tSendMail and use the global variables created by tFlowToIterate.


TRF
Five Stars

Re: Using tSendMail with tJavaRow

Dear TRF,

I want to send multiple records in one email. my template will contain several records.

The problem i am facing is with assigning data. 

What should i add in tJavaRow components: context.FirstName = ??

My table results are like below.

Screenshot_2.jpg

In Email Message: 

"Hello, The input message is " + context.FirstName

Context.FirstName dont have any value. Please advise. Thanks

 

Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

You need to do "context.Firstname = input_row.FirstName" but, because of the job design, you'll get only the last value.

Give an example of the input data and the expected email you want to build.


TRF
Five Stars

Re: Using tSendMail with tJavaRow

Dear TRF,

I am using "context.FirstName= input_row.FirstName" but even dont get last row value.

My Input data is from mySQL Table, it contain following data which is in tLogRow.

I will print simple html table like below in email. My Job Design is in above post, please advise. Thanks

 

ID FirstName LastName

1AAABBB
2ABCDEF
3DEFGHI

 

Update:

Now i added 3 variables in context as ID(int),FirstName(string),LastName(string).

In tJavaRow component added: 

context.ID= input_row.ID;
context.FirstName = input_row.FirstName;
context.LastName = input_row.LastName;

and in tSendMail Message added:

context.ID +"  "+ context.FirstName + "  " + context.LastName

And now in email i am getting null as result.

Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

You want to build a html table to be included into the email message, right?

So, what you're doning is not enough.

Based on your job design, you need to construct the html table row by row into your tJavaRow, like this:

 

String msg = ((String)globalMap.getOrDefault("mailMsg", "<table><tr><th>Id</th><th>Firstname</th><th>Lastname</th>"));
msg = msg +
      "<tr><td>" + input_row.ID + "</td>" +
      "<tr><td>" + input_row.FirstName + "</td>" +
      "<tr><td>" + input_row.LastName + "</td>";

globalMap.put("mailMsg", msg);

Then, in tSendMail, use the global variable to complete the message field and close the html table:

((String)globalMap.get("mailMsg")) + 
"</table>"

 


TRF
Five Stars

Re: Using tSendMail with tJavaRow

Dear TRF,

 

This is strange that in email i am still getting "null ". While in tLogRow i am getting proper results. 

Mapping from tLogRow and tJavaRow is also correct , as below. What possible can be wrong with this.

Screenshot_1.jpg

Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

Looks OK but as it doesn't make the expected job (building a html table), I suggest you to use the code from my previous answer.


TRF
Five Stars

Re: Using tSendMail with tJavaRow

Dear TRF,

 

Now i changed the code like below, but still getting null. I think this tJavaRow is not suitable for this , but alot of people on this forum are using it. I tried many ways still getting null in email output.

context.ID= input_row.ID;
context.FirstName = input_row.FirstName;
context.LastName = input_row.LastName;
String msg = ((String)globalMap.getOrDefault("mailMsg", "<table><tr><th>ID</th><th>FirstName</th><th>LastName</th>"));
msg = msg +
      "<tr><td>" + context.ID + "</td>" +
      "<tr><td>" + context.FirstName + "</td>" +
      "<tr><td>" + context.LastName + "</td>";

globalMap.put("mailMsg", msg);
Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

Correct code in tJavaRow should look like this (sorry):

String msg = ((String)globalMap.getOrDefault("mailMsg", "<table><tr><th>ID</th><th>FirstName</th><th>LastName</th>"));
msg = msg +
      "<tr><td>" + context.ID + "</td></tr>" +
      "<tr><td>" + context.FirstName + "</td></tr>" +
      "<tr><td>" + context.LastName + "</td></tr>";

globalMap.put("mailMsg", msg);

However, this not the reason why you get null in email (and for information, I use a tJavaRow to construct this kind of message in many jobs).

Can you share the tSendMail settings?

Can you also explain why you want to use context variables and what you expect from them?


TRF
Five Stars

Re: Using tSendMail with tJavaRow

1. I saw in another post context variable so i am using them not specific reason.

2. I used System.out.printf and in java debug i can see that everything is printing, msg variable have complete html, though table output is the number of rows, like printing multiple times, but this can be controlled.

3. Now the main issue is null in email, below are my mail settings.

Screenshot_1.jpg

 

In Advance settings selected Html as MIME, and encoding is ISO-----.

Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

Did you hange anything in your initial job design?

Else, add a tJava component with the following code before your tSendMail:

System.out.println(((String)globalMap.get("mailMsg")));

If it print something, everything is OK, you have the mail content you want.


TRF
Five Stars

Re: Using tSendMail with tJavaRow

Dear TRF,

 

Sorry couldnt get "Did you hange anything in your initial job design?". But results of data are ok.

i added tJava as you suggested and getting null again. Please check below screenshot.

Is it possible it have anything to do with this "onSubJobOk"?

Screenshot_1.jpg

 

Five Stars

Re: Using tSendMail with tJavaRow

Update:

in tJavaRow i added System.out.println(msg); then output is as below.

Screenshot_1.jpgScreenshot_2.jpg

Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

Here is my tJavaRow (with correction on html syntax):

 

String msg = ((String)globalMap.getOrDefault("mailMsg", "<table><tr><th>ID</th><th>FirstName</th><th>LastName</th></tr>"));
msg = msg +
"<tr>" +
"<td>" + input_row.Id + "</td>" +
"<td>" + input_row.FirstName + "</td>" +
"<td>" + input_row.LastName + "</td>" +
"</tr>";

globalMap.put("mailMsg", msg);

and here is what tJava print on the console:

 

 

[statistics] connecting to socket on port 3767
[statistics] connected
.--+---------+--------.
| tLogRow_40 |
|=-+---------+-------=|
|Id|FirstName|LastName|
|=-+---------+-------=|
|1 |AAA |BBB |
|2 |ABC |DEF |
|3 |DEF |GHI |
'--+---------+--------'

<table><tr><th>ID</th><th>FirstName</th><th>LastName</th></tr><tr><td>1</td><td>AAA</td><td>BBB</td></tr><tr><td>2</td><td>ABC</td><td>DEF</td></tr><tr><td>3</td><td>DEF</td><td>GHI</td></tr>
[statistics] disconnected

Do you have synchrnized your tJavaRow schema?

 

If not, do it and retry.


TRF
Five Stars

Re: Using tSendMail with tJavaRow

Yes, finally its working. Thank You Smiley Happy

Still not sure what the issue was, My schema was sync, maybe html, but good that its working, i got email with proper table now. now i just need to modify html. 

Forteen Stars TRF
Forteen Stars

Re: Using tSendMail with tJavaRow

Great!


TRF