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: 
Anonymous
Not applicable

Using local variable in tmap expression builder

Hi,

I tried to create local variable(s) inside the expression builder, to get an array of strings as return value:

0683p000009Lv6q.png

 

As I just started using Talend, the idea above is not working.

Error messages:

  • Syntax error on tokens, ReferenceType expected instead  (mouse over the String[] text)
  • Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration (mouse over the numbers_strarray)

My questions:

  • is it possible to create a local variable somehow to be able to  write complex "scripts" instead of input field - output field?
  • if yes, where can I found working example/documentation of it or what to write in the example above to get it work?

I feel I really miss something trivial.

Thanks,

István

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

For the complex scripts (and even complex data types) look at Routines. You can write your own Java classes and use with the expression builder. I have several tutorials of differing complexity on my website, but this one may be of interest for a simple example using a Routine (https://www.rilhia.com/tutorials/creating-random-test-data-using-talend-data-integration).

 

To do what you are trying to do, you need to think in a different way. In the expression builder, you can only use one line of Java code at a time. This makes it trickier to work with, but there are always workarounds (a Routine is a good workaround).  What you are trying to build is a String array. This might be tricky (impossible I would suggest) in the way you are trying it. But you can use a Routine for this OR use an ArrayList to achieve this. Talend actually implements a List data type which is essentially the java.util.List class.

 

Another thing I will suggest is that if you are new to Talend, maybe ask us about your requirement. A lot of the time there is a different way of solving a problem in Talend that new users do not realise. It might be that you are making this a little more complicated than it needs to be.  

 

 

View solution in original post

4 Replies
cterenzi
Specialist
Specialist

Paging @rhall, will @rhall please pick up a white courtesy phone...

Anonymous
Not applicable
Author

I think, I will have to learn java, I cannot avoid it.

 

For the string array declaration/definition I already figured out, what is the right way:

 

String numbers_strarray[] = {"service1", row3.service1};

Regarding, how to return this array is still a question.

 

 

TRF
Champion II
Champion II

Hi,

 

I've personaly never seen it before (not saying it's impossible).

Can you give us some information about your use case? 

What do you expect? How are the input data? What is the expected result?

Anonymous
Not applicable
Author

For the complex scripts (and even complex data types) look at Routines. You can write your own Java classes and use with the expression builder. I have several tutorials of differing complexity on my website, but this one may be of interest for a simple example using a Routine (https://www.rilhia.com/tutorials/creating-random-test-data-using-talend-data-integration).

 

To do what you are trying to do, you need to think in a different way. In the expression builder, you can only use one line of Java code at a time. This makes it trickier to work with, but there are always workarounds (a Routine is a good workaround).  What you are trying to build is a String array. This might be tricky (impossible I would suggest) in the way you are trying it. But you can use a Routine for this OR use an ArrayList to achieve this. Talend actually implements a List data type which is essentially the java.util.List class.

 

Another thing I will suggest is that if you are new to Talend, maybe ask us about your requirement. A lot of the time there is a different way of solving a problem in Talend that new users do not realise. It might be that you are making this a little more complicated than it needs to be.