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: 
GerJea
Contributor
Contributor

Loop over Web Service

Hello,

I have an issue to use a loop to get some Data from a Rest API. I want to run the request until the status field in my response is "completed_ok". If the status is "in_progress" I want to continue. I have no problem to get those fields but I don't know how to configure the loop. I would like to set a Boolean global variable to "true" just before the loop, run the web service and then set this variable to false when I get my correct status and make the loop to stop. My problem is that I don't know how to include the web service inside the loop.

Thanks in advance for your help !

0693p00000BDE31AAH.png

0693p00000BDE5CAAX.png

Labels (5)
4 Replies
GerJea
Contributor
Contributor
Author

Hello, I managed to solve my problem using empty tJava and On_component_ok trigger. I hope this solution can help someone!

First part of the job:

0693p00000BDSRWAA5.pngFirst, I'm putting my input flow into a global variable.

0693p00000BDSXtAAP.pngThen I will iterate until the condition on my loop is respected, the global variable "Status Assistant" will be null at the beginning so it will iterate.

0693p00000BDSNUAA5.pngThen using the trigger On_component_ok and two emtpy tJava, I can retrieve the input flow that I stored in a global variable and run the web service to get my status.

0693p00000BDSbCAAX.pngSecond part of the job:

0693p00000BDSbbAAH.pngI will use a tXmlMap to get my status from the web service response and if it’s “completed_ok”(the status that I want to get) I will set the global variable “StatusAssistant” to “1” and the loop will stop otherwise it will continue to run.

0693p00000BDSgCAAX.png0693p00000BDSN5AAP.pngHave fun !

Prakhar1
Creator III
Creator III

You don't need the "Declaration" or the "Iteration" values. What you want is a variable in the "Condition" that is a Boolean that evaluates to 

true and is set to false when you are wanting to end the loop.

In this case you should create a context ( for ex. FLAG) and change it's type to Boolean and make it false by Default.

Now we need to change the FLAG value when you get the "Correct" status.

So, you can use below java code in tJavaFlex to change the Flag value.

if (status == "Completed")

{

context.flag = true;

}

No need of else condition, Let me know if this works or not.

You can also tell me the variables name so i can make a clear java code.

 

Reference link : https://stackoverflow.com/questions/25041657/how-to-end-tloop-when-desired-criteria-reached#:~:text=put(%22loop%22%2Ctrue,%22Condition%22%20in%20the%20tLoop.

 

 

.

GerJea
Contributor
Contributor
Author

I tried with a flag and it works also ! Thanks you for your answer, it was super clear !

Prakhar1
Creator III
Creator III

Glad it also worked and thankyou for explaining your way also.