Help

Update column values to null with script (updaterecordasync)

1331 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Rainer_Sundjaja
4 - Data Explorer
4 - Data Explorer

Hi, I am new to scripting. I want to set all the values of column(Duplicates?) to null.

How do I do that? Here is my code but it seems that there is an issue with query.recordIds in line 3.
The error is no overload matches.

var table = base.getTable("Table 1");

var query = await table.selectRecordsAsync();

table.updateRecordAsync(query.recordIds, {'Duplicates?': null})
2 Replies 2

Welcome to the community, @Rainer_Sundjaja! :grinning_face_with_big_eyes: There are several errors in your code:

  1. Any method ending in “Async” needs to be called using the await keyword. If this keyword is omitted, the results could be unpredictable/incomplete.
  2. The updateRecordAsync method is only designed to update a single record. There is a similarly-named updateRecordsAsync method that’s specifically designed for updating multiple records.
  3. Even if you use the correct method, you can’t just pass an array of record IDs to update the same field in all of them. What you need to pass to updateRecordsAsync is an array of objects—one object per record—with a specific object structure that indicates which record to update and which field(s) to modify.

Also, while this isn’t technically an error (yet), the selectRecordsAsync method requires an object to be passed as an argument. This object should contain the names of fields that you wish to retrieve from the table. While old versions of the method didn’t have this requirement, my understanding is that the method will eventually be updated so that it truly is required (the strikethrough you see on the method name in the script editor is there to indicate to you that you’re not using it correctly).

I strongly suggest becoming familiar with the scripting API documentation (available online or at the bottom of the script editor), which can help you understand more about the various requirements involved as you write scripts.

In the meantime, here’s a modification of your script that will do the job:

const table = base.getTable("Table 1")
const query = await table.selectRecordsAsync({fields: ["Duplicates?"]})
let updates = query.recordIds.map(id => {
  return {
    id,
    fields: {
      "Duplicates?": null
    }
  }
})

while (updates.length) {
  await table.updateRecordsAsync(updates.splice(0, 50))
}

Thank you so much for the amazing explanation!!!