Help

Programmatically loop through all fields in a record

4103 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Andrew_Heine
5 - Automation Enthusiast
5 - Automation Enthusiast

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?

3 Replies 3
Andrew_Heine
5 - Automation Enthusiast
5 - Automation Enthusiast

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

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:

CONSOLE.LOG

  1. :arrow_forward: (10) [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]

  2. 0: “0”

  3. 1: “1”

  4. 2: “2”

  5. 3: “3”

  6. 4: “4”

  7. 5: “5”

  8. 6: “6”

  9. 7: “7”

  10. 8: “8”

  11. 9: “9”

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.