Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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 !
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:
First, I'm putting my input flow into a global variable.
Then 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.
Then 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.
Second part of the job:
I 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.
Have fun !
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.
.
I tried with a flag and it works also ! Thanks you for your answer, it was super clear !
Glad it also worked and thankyou for explaining your way also.