Hi all
I have a table, which has lots of PDF’s with random filenames. I’d like to batch rename them into Determination.pdf
I’ve had a look at other similar posts, but the script keeps saying:
ERROR
TypeError: Cannot read properties of null (reading ‘length’) at main on line 9
Here’s the modified script by Justin_Barrett which I found here.
// Setup
const mainTable = base.getTable("Projects | Applications")
const mainQuery = await mainTable.selectRecordsAsync()
// Build new attachment data
let updates = []
for (let record of mainQuery.records) {
let attachments = record.getCellValue("Determination")
if (attachments.length) {
updates.push({
id: record.id,
fields: {
"Determination": [{
url: attachments[0].url,
filename: ("Determination.pdf")
}]
}
})
}
}
// Update records
while (updates.length) {
await mainTable.updateRecordsAsync(updates.slice(0, 50))
updates = updates.slice(50)
}
What have I done wrong? Thanks
Also, once I’ve batched renamed them all, is it easy to convert the script above into an automation every time a new PDF is attached to a new record?
Thanks!