Problem with reclist to excel

Problem with reclist to excel

I have one record list with 'x' values, when i create excel with this record list the last value of record list is the first and last in the excel.

record list:
1 a
2 b
3 c
4 d

Excel result:
4 d
2 b
3 c
4 d

The code is one foreach one assign and one ListAppend, at the end of foreach the RecordList it's correct. What's the problem?

best regards

Diogo Coelho

Hello Diogo

The output suggests that you're using the current record list to assign the new values and add it to the list. Can you check which record you're using in the assign?

Ideally, you should use a record variable in the assign, and append that record to the record list. If you're using a record within the record list in the assign, then you're actually assigning the values directly in the record list and cause data being overwritten.

If in doubt, can you share the logic of that foreach?


Hello Miguel,

Thanks for your answer... yes, i think i am using the current record, but i don't understend how...

This is the logic:

One query, foreach run returned list of query.
The next step is Assign, i assigns the current returned list to record list (X) and after step is ListAppend this record list (X).

I attach print of Logic.

Hello Diogo,

As I suspected, you're using the current record of the list you're building to assign the new values. Since the list you're creating is not being iterated, this means that you're always using the first record to assign the values, and then append to the same list. That's why the last record always shows also in the first record.

What you need to do is create a new local variable, of type Record for the same entity type as the list.

Then, change the assign to use the new local variable to assign the values.

Then change the list append to append the new variable on the ExcelList variable.

This way, you're not changing the current record of the ExcelList during the assign.

Hope this helps.

Thanks Miguel, the problem is solved...