@Marouane_EL_BAHIR
But by the way, you may not really have to use custom javascript for such a purpose…
You could do a combination of MAP(), SPLIT() formulas to achieve this without the javascript.
I am not 100% sure what your goal is from this script, but example:
If a csv is formated as this:
header1,header2,header3/
cell1,cell2,cell3/
cell4,cell5,cell6
Formula that could theoretically work:
MAP<row>(SPLIT(data.myCsv, "/"), BUILD_OBJECT(MAP<cells>(SPLIT(row, ","), {key: SPLIT(SPLIT(data.myCsv, "6/")[0], ",")[index], value: cells}), "key", "value"))
*you can copy the above single line, to paste it into the formula editor and below I try to explain
MAP<row>(
SPLIT(data.myCsv, "/"),
BUILD_OBJECT(
MAP<cells>(
SPLIT(row, ","),
{key: SPLIT(SPLIT(data.myCsv, "6/")[0], ",")[index], value: cells}
),
"key", "value"
)
)
I am not convinced that this will work as I didn’t test it, but in theory what this whole thing does?:
We get the csv file and split it into rows with the SPLIT(data.myCsv, “/”) formula. The outermost MAP() then will go through each of these rows (hence we use the alias “row”)
And for each row it will “Build an object” from the values of the current row’s cells, and the header row’s cells as the keys. That’s what we want, right?
This is done by another MAP() which is the equivalent of your internal FOR loop. But of course to feed the information of the header row we have to access it via its static [0] index in the list of the rows. Then we also need to split that into separate cells, this is done by the 2 SPLIT(SPLIT()) formulas. We find the correct header for our cell’s value by feeding it the same index as the index of the cell. And we also get the value of the cell as referred to in the “cells” alias.
In the end we tell the “BUILD_OBJECT” formula that it should look for the keys in the “key” property of the list of objects above and the values in the “value” property.
Let me know if this solves your issue with a no-code approach, or if you face any other problems.
*#AGisCool, I mean this is a truly powerful tool if you master the formulas as well as the style and the positions tab