hi there,
i tried to use the code service for a query in google sheet with multiple columns.
I found a script in flowxo community which i changed for my purpose and it looks like this:
var resultCount = {{search_rows.results_count}};
var row = inputs.row.split("\n");
var i;
var searchTermColor = inputs.searchTermColor;
var searchTermTipar = inputs.searchTermTipar;
var searchTermCantitate = inputs.searchTermCantitate;
var searchTermFormat = inputs.searchTermFormat;
var regExColor = new RegExp(searchTermColor, “gi”);
var regExTipar = new RegExp(searchTermTipar, “gi”);
var regExFormat = new RegExp(searchTermFormat, “gi”);
var regExCantitate = new RegExp(searchTermCantitate, “gi”);
var searchColor = inputs.searchColumnColor.split("\n");
var searchFormat = inputs.searchColumnFormat.split("\n");
var searchTipar = inputs.searchColumnTipar.split("\n");
var searchCantitate = inputs.searchColumnCantitate.split("\n");
var maxCantitate = 100000;
var data = [];
for(i = 0; i <resultCount; i++) {
if (Number(maxCantitate) >= Number(searchCantitate[i]) && Number(searchTermCantitate) <= Number(searchCantitate[i])) {
var maxCantitate = searchCantitate[i];
}
}
for(i = 0; i <resultCount; i++) {
if (searchColor[i].match(regExColor) && searchFormat[i].match(regExFormat) && searchTipar[i].match(regExTipar) && Number(searchCantitate[i]) == Number(maxCantitate)) {
data.push(row[i]);
}
}
resolve(data);
the output is like this:
[
“serviciu: carti de vizita, cantitate: 2000, tipar: fataverso, format: 90x50cm, color: color, pret: 0.35, reducere: 0.28”
]
(including straight brachets).
how can i get the data parsed?
i tried the formula {{execute_code.result__pret}}, as all they say, but is null the result.
think is something because of the json format
i tried in the scrpt to change
resolve(data);
to
resolve(JSON.parse(data));
but it returns errror. “Script Error: Unexpected token s in JSON at position 0”
can you help me?
i think is because of the definition: “var data[];” but i dont know how to change it in a pure json output.
can you help me? pls.