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

Loop in tRestClient (check value in row)

Hello everyone!

 

I has this flux: tloop -> iterateToFlow -> RestClient.

I need execute this flux when there is value in execution.

 

0683p000009M7hH.jpg

 

I need tloop to just execute while it comes back from api, if there is no return I need to stop loop

 

0683p000009M7aM.jpg

I try put tjava, but I don't know where to put the component.

 

This api request has 94 pages, this loop start 1 and stop at 94 based on page records.

 

0683p000009M7hM.jpg

 

Each page brings me 100 'records', if I loop it works fine, but I need it automatically as it will come online on a server using crontab.

Labels (5)
11 Replies
vapukov
Master II
Master II

Hi

 

you can use tLoop (While)

 

for example:

define boolean context or global variable

context.do_iterate = true;

than in tLoop use single condition

context.do_iterate

 

loop will work infinite until the condition is true

after tExtractJSONFields you can add tJava component and reset variable if data is empty

context.do_iterate = false;

Anonymous
Not applicable
Author


@vapukov wrote:

Hi

 

you can use tLoop (While)

 

for example:

define boolean context or global variable

context.do_iterate = true;

than in tLoop use single condition

context.do_iterate

 

loop will work infinite until the condition is true

after tExtractJSONFields you can add tJava component and reset variable if data is empty

context.do_iterate = false;


Sorry for the delay, but how will check if data is empty?
Can you help about code?
In the meantime I'll try to build something

Anonymous
Not applicable
Author

You can link tExtractJsonField to a tJavaFlex, define a counter on tJavaFlex, if the counter is 0, means no data are return.
....tExtractJsonField--main--tJavaFlex
on tJavaFlex:
in the begin part:
int counter=0;
in the main main part:
counter++;

In the end part:
if(counter==0){
context.do_iterate=false;
}else{
context.do_iterate=true;
}

Hope it helps you!
Anonymous
Not applicable
Author

Hello,

 

When I set do_iterate = true, the flow are infinity.

The process doesn't continue for next step.

 

0683p000009M7w2.png

 

Is it correct do_iterate in condition, because how does the process know to do the rest?

Anonymous
Not applicable
Author

Do each API calling will return one page and the page will contain 0 or several records? If it is 0, you want to stop the loop?
Anonymous
Not applicable
Author


@shong wrote:
Do each API calling will return one page and the page will contain 0 or several records? If it is 0, you want to stop the loop?

Yes, I need this. When 0, it stops.

Anonymous
Not applicable
Author

Change the job design as below:
tLoop--iterate--tJava1--oncomponentok-->RestClient-->tExtractJsonField-->tJavaRow--oncomponentok--tJava2

on tJava1:
context.counter=0;

 

on tJavarow:

context.counter++;


on tJava2:
if(context.counter==0){
context.do_iterate=false;
}else{
context.do_iterate=true;
}

//Define another context variable called counter, int type.

Please test and let me know if it works.

Anonymous
Not applicable
Author

I trying to use your model, but I have similar problem. Because tloop -> do_iterate = true, does not go to the next step, becomes infinite.

 

0683p000009M82b.jpg

 

I stopped manual this execution.

Anonymous
Not applicable
Author

Can you upload a screenshot of tRestClient component? I want to see that your each API calling return different response rather than the same response.