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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Exit tLoop by global variable

Hey friends,

First of all let me say i'm new to Talend and making my first steps in now and additionally doesn't have any JAVA coding knowledge.

After this promising start i will explain what i need,have and the problem.

 

i need to create an API connection to store their data into my MySQL DB and to do so i used tRESTClient,

the API limit the results to 30 rows per page, so i need to paginate (i think this is the term) between the pages.

I used tLoop for that and configures it as 'For loop' the problem is that if i set the loop for 10 it might run in the end few times without retrieving any data, cause page 10 in the API is currently empty.

I'm looking for a way to stop the loop if the output is empty.

 

i have created a tJavaFlex component that check if there is data in the out put and store it in globalMap.

But i currently cant config the tloop as while to stop when globalMap=false.

 

 

this is the project:

0683p000009M7XO.png

 

the loop runs 5 times each time the page number increased in tRESTClient.

0683p000009M7ah.png

 

java component that check if there is data out from tMap

0683p000009M7i6.png

 

and here you cans see that when there is data it prints true and for the next pages it print false

0683p000009M806.png

i want to make condition in tloop while "hasData" is true increase the page.

 

appreciate any help

Dima K

Labels (2)
3 Replies
Anonymous
Not applicable
Author

If you use a while loop (in tLoop component , just switch from 'For' to 'While') : you can then use 2 conditions in the 'Condition' field : one for the amount of exec already done (1 to 10) and another one on your global variable : 

Condition for iteration is : currentIteration <= MaxIteration AND hasData==true . This way if one or the other of these conditions are not met anymore, the loop will stop.

You'll have to define MaxIteration as a context or global variable for example, and use the globalVariable you have already created ('hasData')

Anonymous
Not applicable
Author

Many thanks for your reply but i don't quite understand what to do, is there any chance you can create an example and show print screens?
Anonymous
Not applicable
Author

i have edited my answer with further precisions.