Hi all,
I’d appreciate some guidance on how can I change the filenames of my attachments. I have a table with 500 records. Every record has a name and multiple images (attachments).
The attachments have identical file names in multiple records, e.g I might have a file called 1.jpg in one record, then a different attachment in a different record with the same name of1.jpg.
I managed to find a script that does that, but it changes the name only for one attachment. Ideally, would be to create a rule that adds to the current filename, the name from another field.
e.g: Gorge 1 + current filename.jpg
// Setup
const mainTable = base.getTable("Test")
const mainQuery = await mainTable.selectRecordsAsync()
// Build new attachment data
let updates = =]
for (let record of mainQuery.records) {
let attachments = record.getCellValue("images")
if (attachments.length) {
updates.push({
id: record.id,
fields: {
"images": :{
url: attachmentst0].url,
filename: record.getCellValue("Name")
}]
}
})
}
}
// Update records
while (updates.length) {
await mainTable.updateRecordsAsync(updates.slice(0, 50))
updates = updates.slice(50)
}
Thank you in advance,
Victor