Hello, im trying to do a loop like a function while. I need that the loop stop only when a attribute boolean is TRUE, but it is FALSE the loop don’t stop. Can help me? Thank
Hey @Jonathan_Calderon,
Welcome to the Losant forums, we’re happy to have you!
First, I’d really like to get a better idea of your use case. What solution is this while loop solving? Are you looking to execute certain business logic when an incoming device state attribute is true
? How often is this attribute being updated and changing values?
Since it is not possible to implement a true while
loop in Losant if you could provide more information about your use case, I’d be happy to help with a more appropriate implementation.
Thank you,
Heath
Hi, I have an pagination API (Send the information in different pages). I don’t have the number of page that the API has. I think in a function "while "that stop when this API send a void object. This API send me information about device that i create inside the workflow. That’s it my problem. Thanks for the answer
Hey @Jonathan_Calderon,
Thanks for including that additional information.
If you are able to loop through the pages already, I would suggest that you use a Conditional Node to check for a null
or undefined
object or path on the payload.
This being said, I am assuming that you are making the HTTP request (with an HTTP Node) and then using an item on the response body as the loop source for the loop node. If this is the case, the Loop node should stop looping once it has looped over the total number of items in the loop source. Once this is complete, your workflow will then move onto the next node (assuming there is one).
Is this the situation you are finding yourself in?
If you haven’t already, I would highly recommend that you check out Losant University, specifically the module on the Loop Node.
Please let me know if there is any other information I can provide, or if I am misunderstanding your issue.
Thank you,
Heath
There is another option to use a Mutate Node to put a large number (e.g. 10000, or a number guaranteed to be larger than the number of pages you have) on the payload and use it as the source for the loop node.
The idea here is that the number of loop iterations will be greater than the number of pages you receive from the API and the Break Node will eventually end the Loop.
Please let me know if you need more detail.
Thank you,
Heath
Thank you Heath. I solved the problem with your information.