Apr 05, 2021 04:25 PM
Hello All,
I’m attempting to wire up a script to a button field. When the button is clicked this is what happens:
let data = {
"field": "value",
"field": "value",
"etc...": "etc..."
}
this data object is then sent to a webhook via fetch post request
What I have is this:
let pipeURL = "webhook URL here";
let table = base.getTable("GPP Website Leads");
let view = table.getView("Grid view");
let queryResult = await view.selectRecordsAsync();
console.log(queryResult.records)
This works, but only returns the recordID and the first field in the view. I’m sure it’s trivial but I can’t figure out how to loop through and get all the fields & associated values for a given recordID. The I could populate my data object with the fields and the values.
Thanks for the help!
Apr 05, 2021 11:28 PM
Welcome to the Airtable community!
You can get a list of all the fields from the table object. Once you have all of the fields, you need to use getCellValue to get the actual field values for the record.
Apr 06, 2021 07:03 AM
Thank you! I’ll give that a whirl
Oct 03, 2022 11:37 AM
super long and anoying btw
when we will see a beautiful
record: {
field:value,
field:value,
field:value,
}
Oct 03, 2022 12:05 PM
I don’t know, as I do not work for Airtable. If I had to guess, my guess is that Airtable will not implement this.
If you want to see records in that format, you can use helper functions create that format. I actually used such a helper function to create that format around when scripting came out, but I have since abandoned doing so on a regular basis a I no longer find it useful.