Hey Community,
I was getting help a little while ago on a script a month ago, and I’m trying to apply the old script to a new use case, and having a bit of a problem.
I’m having another issue upstream through an integration that is removing the file name. This problem is a bug that doesn’t look like it’ll be fixed in the short term, so I thought if I reuse a name script I’ve been using, it should solve my problem.
The only issue with the script is in the current version it was built to maintain the extension, IE: PDF, MOV, MP4, etc… but I want to completely rename the file via the field I have on my database.
When I’m using this right now, it’s for some reason adding the name of the file at the end of it when the name changes…
I’ve spent nearly 1.5 hours trying to solve this in different ways, but can’t figure it out. Does anyone who is better with scripts know how to change this?
This is what it is currently giving me, and I don’t want the weird stuff at the end… I want it to end at .PDF, which it’s currently pulling from the name field.

// Setup
let config = input.config()
let table = base.getTable("TABLE")
let query = await table.selectRecordsAsync()
let record = query.getRecord(config.recordID)
// Collect record data
let newPrefix = record.getCellValue("NEWNAME")
let files = record.getCellValue("ATTACHMENT")
// Get the extension and add it to the new name
let newFiles = []
for (let file of files) {
let parts = file.filename.split(".")
let ext = parts[parts.length - 1]
let fileNumber = "0" + (files.indexOf(file) + 1)
let newName = `${newPrefix}-${fileNumber}.${ext}`
newFiles.push({url: file.url, filename: newName})
}
// Reattach the item with the new filename
await table.updateRecordAsync(record, {
"ATTACHMENT": newFiles
})
Also,
I suddenly started getting this error on this forum that’s been working for months, but it is not affecting it’s from working, just when I test it. Should I be concerned?
TypeError: files is not iterable
at main on line 13



