Help

Fields parameter in input.recordAsync not working

Topic Labels: Scripting extentions
1704 3
cancel
Showing results for 
Search instead for 
Did you mean: 
David_Lewis
4 - Data Explorer
4 - Data Explorer

Hi there, I am working on creating a user cms for our web app. My goal is gather a record’s information from a button click. I am currently getting the record based upon the click but I am only getting the ‘id’ and ‘name’ as part of the returned record object. Here is the code so far

let table = base.getTable("Users");
let fieldsToInclude = table.fields.filter(field => field.name !== "Update User");
let record = await input.recordAsync('Update user', table, {fields: fieldsToInclude});
console.log(record, fieldsToInclude);

The console output is:

{id: "recmKNtwayYQNFu0K", name: "Kelly"}

 ▶(9) [Object, Object, Object, Object, Object, Object, Object, Object, Object]
0: Object
  id: "fldMqI2JmcuRkwOru"
  name: "First Name"
  description: ""
  type: "singleLineText"
  options: null
  isComputed: false
▶1: Object
▶2: Object
▶3: Object
▶4: Object
▶5: Object
▶6: Object
7: Object
  id: "fldVQSI2xjMjdunEi"
  name: "Initiative"
  description: ""
  type: "singleLineText"
  options: null
  isComputed: false
▶8: Object

Why am I only getting the record id and name even though I pass an array of field objects? I have tried maping the array to only return field ids, then field names but neither seem to work. Any help or insight would be greatly appreciated!

3 Replies 3

Whether or not you include the optional options.fields parameter, you still have to return your own field values separately as input.recordAsync() returns the record instance, which is always {id: 'x', name: 'y'}.

Follow your code with a loop of some sort:

let recordValues = Object.fromEntries(fieldsToInclude.map(field => {
   return [field.name, record.getCellValue(field.id)]
}))
David_Lewis
4 - Data Explorer
4 - Data Explorer

Thank you @Kamille_Parks for responding. What exactly then is the point of the fields parameter for input.recordAsync() if you still have to loop through each individual field to get the values? Is there any other way to gather field values without looping over a list of field names? Thanks again for your time in helping answer my questions!

From the documentation:

Generally, it’s a good idea to load as little data into your script as possible - Airtable bases can get pretty big. The fields option lets you make sure that only data relevant to you is loaded.