Mar 12, 2022 09:48 AM
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})
Mar 12, 2022 07:27 PM
Welcome to the community, @Rainer_Sundjaja! :grinning_face_with_big_eyes: There are several errors in your code:
await
keyword. If this keyword is omitted, the results could be unpredictable/incomplete.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.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))
}
Mar 19, 2022 09:55 AM
Thank you so much for the amazing explanation!!!