Hi all,
Is there an action where a user can upload a csv of data, i can import it so then I can apply some of the AI tools? I’d want it set up so a user could only upload 25 rows at a time. Thanks!
Hi all,
Is there an action where a user can upload a csv of data, i can import it so then I can apply some of the AI tools? I’d want it set up so a user could only upload 25 rows at a time. Thanks!
I wish. Need to build it yourself using file upload → parse it out (variety of ways to do this) → Glide API Add Row
Can you help me with the parsing bit? I’m guessing I need some kind of api call or something?
Allow the user to upload the file to a file picker, pointing to a user-specific column.
Use a Javascript column to parse it (courtesy of @Robert_Petitto ).
if (!p1) {
return "";
}
const data = await fetch(p1);
const csvText = await data.text();
let adjustedText = csvText.replace(/"([^"]*)"/g, (match, p1) => {
return `"${p1.replace(/,/g, '<COMMA>').replace(/\n/g, '<NEWLINE>')}"`;
});
const lines = adjustedText.split("\n").map(line => line.split(','));
lines.forEach(line => {
line.splice(10, 1);
});
const semiColonLines = lines.map(line => line.join(';'));
return semiColonLines.join("\n").replace(/<COMMA>/g, ',').replace(/<NEWLINE>/g, ' ');
With p1 being the URL of the file the user uploaded.
This is assuming you only need to “apply some of the AI tools”, not adding any rows. If you can go into more details about your use case we can help more.
Basically I want to give the user the ability to upload 25 rows of data with 5-10 fields, and then I’ll create a new AI field that combines some of the data. So in your JS example that will give me one row, but how do i get all the rows?
His JavaScript example will read the entire CSV file and return the whole thing in a single cell.
If you want it split across multiple rows, that’s a little bit of extra work.
Right…That’s why I’m asking how to do that
What I would probably do is pass a RowIndex value as an extra parameter to the JavaScript, and then modify the code so that instead of returning a joined list of all CSV lines, it just returns a single line which corresponds to the RowIndex index value in the lines
array.
I would add a helper table, add 25 rows to that.
Add a rowID column, and a lookup column that points to that rowID column to get a list of rowIDs.
Use a “find element index” column, find the rowID of the current row against that list of all rowIDs. You’ll get a list of indexes that start from 0.
Find a way using single value or template column to cast the CSV that is generated from the JavaScript column to all rows in your helper table.
Then finally, use JavaScript to get a “row” from the CSV onto each row of your helper table.
This is the process many of us experts use nowadays.