Bug in While Loop?

======== TEMPLATE BUG FORM ========

Wappler Version: 3.0.1
Operating System: Windows 10

Expected behavior

What do you think should happen?

Actions should be available under the While Loop as they are under a Repeat Loop
I can create this condition to count records in a repeat loop

Actual behavior

What actually happens?

If I try to do the same in a While Loop I can’t access the records as the action step isn’t available in the data picker

How to reproduce

  • Detail step by step guide to reproduce the issue
  • A screenshot or short video indicating the problem
  • A copy of your code would help. Include: JS, HTML.
  • Test your steps on a clean page to see if you still have an issue

Add a while loop in a server connect file, add a condition within it (or any step that needs to access the steps in the While Loop) and try to access the steps in the While Loop

Can you post a screenshot of the exact steps you have in your while loop and explain what/where are you trying to access, and what exactly are you trying to do with the while?

I’m trying to sync records from the Xero API, the records return in batches of 100 and the API offers a paging option by appending ?page=‘page number’ to the endpoint.

If there are 100 records I want to add 1 to the page number and run the API call again.

If there are less than 100 records the call is complete and I want to set the nextPage tag to “n” to stop the While. There is no way to get the number of records expected from the call at the outset.

If I try to set the condition to count the records returned by apiJNL I can’t see the action step for the While Loop or anything under it as I can in a Repeat Loop. I’ve added the condition in manually but this is what I’m thinking it should look like.

Also you don’t seem to be able to output from a While Loop so maybe my understanding of it’s usage is wrong?

What is the value of y?

You are setting your nextpage variable to have a value of other variable called “y”

But it is probably empty do it will never work.

Maybe you mean the string “y” then you will have to put it in quotes.

Great thanks, yes that helps … I get data again! But I can only see 100 records at a time, I assume because the ‘API Action: apiJNL’ outputs rather than the While Loop as a whole…

I think the properties of a while should be the same as a repeat but they’re blank so I can’t set to output all the records…

My next step would be to either run a repeat after each run of the API action, or after the while, to insert the entries into the DB. Without the While showing in the data bindings I can’t see anyway I can manually add a repeat, with expression and output to do this?

I don’t know if this helps or not, but I’ve seen a lot of times where I update a value in a repeat and it doesn’t show up where I need it. I then refresh the actions scripts, and then reopen the script and then it pops up there. Seems like you shouldn’t have to refresh. But when in doubt I always do that.

Thanks Baub,

Have given it a go but no joy! Also tried restarting and a fresh project but can’t seem to get the While loop to show in the data bindings panel at all.

Anyone able to confirm this as an issue, or if it’s just something on my setup? Am struggling to see any workaround atm!

Just been having another go at resolving this:

This is the server connect:

and this is the output of the set values nextPage (boolean) and page (number):
{"nextPage":false,"page":1}

There are 2 issues I can’t get past. Firstly counting the records doesn’t work (if I return the apiInvoices action I get exactly 100 records so it should increase the page number instead of listing nextPage as false). I think the syntax is right but I wonder if I can’t access the step with manual code for the same reason it doesn’t show in the data bindings?

Also I can only output the API action step and not the while loop as a whole, so even if I get the loop to work I can only ever see 100 records?

I think you are getting caught with scope of variables. The set values inside of whiles/repeats will have a local scope, but you need global.

Here’s what I think you want:

But the important changes are in the properties:

Here are the parent set values:

And the set value actions inside the while

Now, in my example, it will loop for ever because I hard coded the fake value, but I’m assuming you have something going on in the api to manage it for real.

Thanks Ken that’s really helpful. I’ve changed those variables and also adjusted the syntax of the count to:

apiInvoices.data.Invoices.count()

and I get all records returned. I still can’t see the While steps in the data bindings, but this is OK if I can manually add code which it seems I can (just makes me more prone to errors!)

Are you able to access the steps in the While Loop from the data bindings?

I’m also still unable to output from the Where loop, I can change the toggle using the option at the top of the Action Steps pane but it won’t actually output. I’m just trying to ascertain if this is a bug or something I may be able to resolve? I can output anything within it (so the values, the paged API records etc) but not the thing as a whole.
image

No, it seems like there is a bug in that.

As to the output, what are you expecting see from the While loop output, other than the children outputs?

I guess I assumed it would work the same as a repeat which has the option of outputting the whole repeat data set.

Given it didn’t seem to be working quite right I just want to be sure what it should be like so I can plan the relationship with the API appropriately.

So the data picker issue I can work around with manual code (though it would be great if this could be fixed at some point).

Now I can access all the records I can add an insert in each loop to save them for retrieval later. If this is by design then there’s nothing to be fixed!

Thanks so much for your help!

So I’d hoped I could move this forward by just manually coding the actions in the While loop that I can’t see in the data picker.

This is the server connect:

I can code most elements within the While Loop but the selection for the Output Fields in the Repeat are automated. I can access the fields for the output with an expression of:

apiInvoices.data.apiInvoices.data.Invoices

image

But this returns no records:

image

Or if I change it to

apiInvoices.data.Invoices

Then I can’t access the Output fields:

image

but I do get data returned (it’s just empty)

I think that’s all avenues exhausted and leaves the While loop unusable for this use case at the moment (on the plus side the Xero authentication and refresh is now pretty slick!).

Anyone from the team able to confirm there’s an issue in the While function and any possible timeframe for a fix?

Thanks!

Could you check if this is still an issue, as we recently improved the data bindings picker to be more smart with previous steps data scopes

Had a quick look at this this morning and it does look like all the data is now available in the pickers which is great!