Export to CSV : Data is not an array

Hello dear Wappler superstars !

Here is the use case I’d like to implement :

  • Read CSV file
  • Edit some values
  • Write CSV file

I’m currently blocked on export as the “export CSV” action in server connect expects an array.
From what I understood, this action is intended to be used with a query result as an array.
But I don’t need a database operation for this…
I’m wondering if there is a trick to build an array from the modified value of my current CSV.

Thank you very much for your help !

If you use Set Value within a repeat then the result will be an array of the name given to the set value stage.

However a bit more info as to how you actually modify the value before wanting to export would help as this is a relevant factor, perhaps a screen grab of your server action?

I’m not sure how you’re approaching this, but I think the simplest option would be to import the data into a database table, edit in the normal way (using server connect’s update facility etc.), and then export the new data - ie just using features which are available in Wappler.

Wappler doesn’t have any features to read or write to text files as it stands. Hopefully it will at some point. You can vote for this feature.

Context :
As there is no way to write to a file directly, I wanted to use the csv import/export function to store a simple “counter” (used for a script that need to resume from his last execution).

Indeed, putting the logic within a repeat function did the trick.
Thanks @Hyperbytes !
Screenshot below in case it can help anyone else struggling.

Now…
I don’t know if it’s a bug but I can’t call the import/export function multiple times…

Export function doesn’t insert any ending separator at the end of each line.
Thus the import function fails on the next call :
{“data”:{“csvImport1”:“current_counter is missing in /dmxConnect/api/datasource/csv/comments_counter_lb.csv”}}

// Initial file content (import works)
current_counter;
3;

// Export output (causing next import to fail)
current_counter
4

Adding the missing “;” manually solves this but the separator should be added automatically I guess.

Thanks Tom, I voted for this.

I implemented the DB “shotgun” approach as a workaround for now, even if I’m not so happy about it :D.