Called EndIteration while the list was not being iterated...

Called EndIteration while the list was not being iterated...

  

Hi,

This is a screen action I have that will insert in the db what I have inside a table list when the Id = 0, aka I just entered the data inside the table to get sent to the db, but I'm getting the error "Called EndIteration while the list was not being iterated...", using a breakpoint I noticed it goes all the way past the ajax refresh and thru the "End" directly into the "All exceptions" action. If I remove the ajax refresh it will insert in the db without a problem, just not refreshing the table to have the new inserted record, any idea?

Hi Fabio,


You are ending the ForEach if a condition is met. If I'm correct, you are not allowed to do that. 

You might want to save data that you want to use in a certain iteration. After the for each, you can check of the data is filled, and perform the actions at that point. The solution may look something like this:

Please let me know if this worked for you.


Sam


Edit: Also, may I suggest you to take a look at the best practices. Your code will be easier to read if you keep the flow 'vertical and tidy':
https://youtu.be/sIlEUJ_2kLE?t=1009

Solution

@Sam: you're wrong, that is allowed.

@Fábio: the problem is that you are iterating over the List that is also used as Source Record List of your Table Records. This is of itself not a problem, but the Ajax Refresh triggers an iteration over that same list (so it can display all data), but since the For Each in your code wasn't finished yet, you get a nested iteration, which leads to your problems. So that's why it works without the Ajax refresh.

To solve this problem, in this specific case, I would handle it a bit differently. First, I think it's weird that you iterate over the list until you encounter a NullIdentifier() Id, then stop: I'm not sure about your data, but doesn't that mean that the Counter will have an invalid value, or are you counting how many records there are that don't before the NullIdentifier() Id? Secondly, I would use the List Actions to get what you want. If you want to safe the first record with a NullIdentifier() for Id, you can perform a ListFilter on the list, and save the first record. If you want to count the number of records before that record, you can perform a ListIndexOf with the same condition, and you'll have the same count.


Solution

Kilian Hekhuis wrote:

@Sam: you're wrong, that is allowed.

@Fábio: the problem is that you are iterating over the List that is also used as Source Record List of your Table Records. This is of itself not a problem, but the Ajax Refresh triggers an iteration over that same list (so it can display all data), but since the For Each in your code wasn't finished yet, you get a nested iteration, which leads to your problems. So that's why it works without the Ajax refresh.

To solve this problem, in this specific case, I would handle it a bit differently. First, I think it's weird that you iterate over the list until you encounter a NullIdentifier() Id, then stop: I'm not sure about your data, but doesn't that mean that the Counter will have an invalid value, or are you counting how many records there are that don't before the NullIdentifier() Id? Secondly, I would use the List Actions to get what you want. If you want to safe the first record with a NullIdentifier() for Id, you can perform a ListFilter on the list, and save the first record. If you want to count the number of records before that record, you can perform a ListIndexOf with the same condition, and you'll have the same count.


Greetings Folks,

Nice to read & upgrade our dev perspective towards Outsystems.

Thanks @Kilian Hekhuis.

Not a solution but just to share a Scenario where I came across same Issue in Mobile Application.

I have a REST API & certain for-loops used in the Action, where I am dumping the Conditional Data from REST API Response to my Local Entities.

While I had a Monkey Testing on Mobile app, I faced same issue whenever the REST API Call where going multiple times. Due to Multiple API Call my Data Actions where Executing Number of times.

Thus had prevented the API calls & didn't  faced the issue.