39
Views
7
Comments
List.Current starting from end
Question
Platform Version
11.10.0 (Build 22910)


One of my application started behaving abnormally and after quite an investigation, we found something very strange. The Current index by default is pointing to LAST element instead of first.

No, it is NOT inside a for loop. The data is coming from an API and my code was using current element (as a reference to 0th index by default). Am I the only one? 



EDIT 1:   the scenario is something like this. I have an action A that calls an api X, the output of the API which is a list of structure S is passed on as S1 to an action B where it is further processed. The above observation is from action B for the list S1. 

Rank: #64

Hi Goldy,


That is a strange situation, I was also under the impression the current would point to the first position of the list and after a query I know it is the first position.

In any case, what I usually do when I need the first position (and to explicitly get the first position) is using [0] instead of .Current, something like in the example below:

List[0].Title


You just need to check first if the list is empty, to avoid an error of trying to access the first position when there isn't one.


Hope it helps.


Regards,
João

Rank: #2230

Joao,

This happened after a recent platform upgrade. I think there may be others like me. Someone from platform team should recheck. 

As for the fix, yeah thats the workaround I used, albeit unhappily.

Thanks

Champion
Rank: #105

Hi Goldy,

The Current of a list is a runtime property which is initialized when a sql or aggregate is executed, or when you iterate a list using a ForEach.

Whenever you click on a line of a List Records, the List.Current starts pointing to that line. Which means the List.CurrentRowNumber become the Row number of the clicked row. 

Regards,

Swatantra

Hi Goldy,

Usually when you fetch any array from API the current row number points to the last element only.

You can check for BOF property for the aggregate list or API response array as below - 

This returns true if the record position of Current is before the first record of the list and the list is not empty.

Based on the response you can assign the or pass the value to the next function.


Thanks,

Unnati 

Rank: #2230

Can you point me to any documentation that says List.Current would be referencing to the last element in case of API call? 

If that is true, we cannot use For loop on a list response from an API call without changing the default reference of CurrentRowNum to 0.

Hi Goldy, 

This should not be the case. The for loop will start from the beginning of the list regardless on where the pointer was before the loop.

You can use that loop as you want.

Thanks,

Unnati

Rank: #129

Hi Goldy,

I had never witnessed this behaviour, so I had a little test.

So most of the time, the list from the api, and also any follow up list I assign or append the data to, has 0 as current.  

But I find in one case, the api output list has current on the last item and not the first : after it was the source of an AppendAll node.

So maybe that's the case in your logic after calling the api ??

Anyway, I would also like to add, that your concern that you wouldn't be able to do a ForEach is not correct, the ForEach will iterate from beginning to end, regardless of where the current is right before the ForEach.


Hope this helps you further,

Dorine