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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Papademuchos
Creator
Creator

How to use table query results in tRowGenerator

Hello,

 
If I'm in the wrong board, I apologize - I'm new to Talend and the Community.
 
I have a functionality question with tRowGenerator.  I'd like to generate random values based on a query from a table.  Is this possible to do?  If so, how?
 
If I hard-code a string of values, this works:
image.png

 

I've tried variations using a context variable, thinking I can load from the table the list, denormalize it, and then load to the context variable.  Once that is done, tRowGenerator does it's thing.  But I can't get that to work:

image.png

 

I've tried changing the type from String to List, but can't seem to get it to work.

When I hard code the list, TOS generates this following Java code:

 

public String getRandomCredentials() {

String[] CredentialsTable = new String[] { "MD", "DO",
"FNP", "AGNP", "DDS" };
java.util.Random randomtRowGenerator_1 = new java.util.Random();
return CredentialsTable[randomtRowGenerator_1
.nextInt(CredentialsTable.length)];

}

 

But when I use a context variable, it doesn't "randomize it".  It just returns the values in the context variable as a single string:

 

public String getRandomCredentials() {

return context.Credentials;

}

 

Any help is appreciated!

Labels (2)
2 Replies
Anonymous
Not applicable

Hi @Papademuchos  and welcome to the Community!

 

I'm afraid your screenshots are not available to view. I have checked the HTML and it looks like you are sharing from Google. This does not allow others to view this. Could you use the Photos button at the top of the post window and add these?

 

Regarding your question, I think you may need to use a tMap and call the methods using Java in-line IFs to do this. I may be wrong since I am missing the images, but you might want to try that.

Papademuchos
Creator
Creator
Author

Hello, hopefully these images will come through better.  The first one is showing the literal string in the Expression Value in tRowGenerator.  It accurately randomizes my five values among the generated rows:  "AGNP","DDS","DO","FNP","MD".

 

0683p000009M6e0.jpg

 

The second one is my attempt to pull the values from a database table and put them into a context variable.  I can do that part just fine, but tRowGenerator doesn't see them as a list of values, but a single value.

0683p000009M6uQ.jpg