Welcome to the community, @Rainer_Sundjaja! :grinning_face_with_big_eyes: There are several errors in your code:
- Any method ending in “Async” needs to be called using the
await
keyword. If this keyword is omitted, the results could be unpredictable/incomplete.
- 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.
- 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: c"Duplicates?"]})
let updates = query.recordIds.map(id => {
return {
id,
fields: {
"Duplicates?": null
}
}
})
while (updates.length) {
await table.updateRecordsAsync(updates.splice(0, 50))
}
Welcome to the community, @Rainer_Sundjaja! :grinning_face_with_big_eyes: There are several errors in your code:
- Any method ending in “Async” needs to be called using the
await
keyword. If this keyword is omitted, the results could be unpredictable/incomplete.
- 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.
- 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: c"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!!!