May 04, 2021 10:45 AM
I am pulling the records from a table, and I am able to loop through all the records, but in the API documentation I can only see examples for pulling specific cell values by directly calling each specific field name. In order to future-proof the script in the event that someone changes field names at some point, I’d like to programmatically loop through all the fields without having to know what all the field names are and hard-coding them in. Anyone know how to do this?
May 04, 2021 10:55 AM
You loop through the fields at the Table level, not the Record level:
for (let field of inputEventsTable.fields) {
console.log(`${field.name}`);
}
Of course I figured it out 10 minutes after posting here lol
May 04, 2021 05:16 PM
Ok still not working. ‘field.name’ doesn’t return the name as a string and getCellValue() requires the field name string as an input. I can’t for the life of me figure out how to get the string version of the field name here. It will spit out in console.log as what looks like a perfectly good string but running Object.keys() on the field name just gives an array where the key and value are just a sequence of integers.
Here’s a sample of the code:
for (let field of inputEventsTable.fields) {
fieldNames[i] = field.name.toString();
i++;
console.log(Object.keys(field.name));
}
and the console.log of the Object.keys bit spits out this:
:arrow_forward: (10) [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
0: “0”
1: “1”
2: “2”
3: “3”
4: “4”
5: “5”
6: “6”
7: “7”
8: “8”
9: “9”
May 04, 2021 05:24 PM
field.name
is a string, assuming that field
is a field object. getCellValue()
can also take either the field name, the field id, or the field object.