Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

0683p000009Lwpb.jpg

 

Please advise what i am doing wrong. Thanks

Labels (3)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

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.

View solution in original post

16 Replies
TRF
Champion II
Champion II

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.

Anonymous
Not applicable
Author

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.

0683p000009Lwpl.jpg

In Email Message: 

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

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

 

TRF
Champion II
Champion II

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.

Anonymous
Not applicable
Author

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

1 AAA BBB
2 ABC DEF
3 DEF GHI

 

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.

TRF
Champion II
Champion II

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>"

 

Anonymous
Not applicable
Author

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.

0683p000009LwrO.jpg

TRF
Champion II
Champion II

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.

Anonymous
Not applicable
Author

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);
TRF
Champion II
Champion II

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?