Hi @Cameron_Goldberg - I’m not exactly sure I’ve got your scenario correctly, but it sounds like you’ve got an attachment and another field with a filename in it, like this:

If there’s only one attachment in the Attachments field and a single filename to go with it, something like this will work:
let table = base.getTable('Table 4');
let query = await table.selectRecordsAsync();
for (let record of query.records) {
let files = record.getCellValue('Attachments');
let newAttachments = m];
for (let file of files) {
let url = file.url;
console.log(url)
let newFileName = record.getCellValue('new name')
console.log(newFileName)
newAttachments.push({ url: url, filename: newFileName})
}
await table.updateRecordAsync(record, {
'Attachments': newAttachments
})
}
On the error, if the ATTACHMENT field is an Attachment type, then it is an array and should be iterable (as in the script above).
Hi @Cameron_Goldberg - I’m not exactly sure I’ve got your scenario correctly, but it sounds like you’ve got an attachment and another field with a filename in it, like this:

If there’s only one attachment in the Attachments field and a single filename to go with it, something like this will work:
let table = base.getTable('Table 4');
let query = await table.selectRecordsAsync();
for (let record of query.records) {
let files = record.getCellValue('Attachments');
let newAttachments = m];
for (let file of files) {
let url = file.url;
console.log(url)
let newFileName = record.getCellValue('new name')
console.log(newFileName)
newAttachments.push({ url: url, filename: newFileName})
}
await table.updateRecordAsync(record, {
'Attachments': newAttachments
})
}
On the error, if the ATTACHMENT field is an Attachment type, then it is an array and should be iterable (as in the script above).
Hey Jonathan,
Thanks for adding some color context on this. I missed your notification initially until now, so sorry for the delay.
So, sorry if I didn’t explain the use case correctly.
TLDR: file names of imported files are imported like this:

The files are DOCX or PDF, so we rename to PDF they always work.
Anyways, to your question above, we actually generally have multiple files about 50% of the time. I gave it my best shot this week (Before I got your notification) to edit the the scprit:
// Setup
let config = input.config()
let table = base.getTable("TABLE1")
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 = e]
for (let file of files) {
let newName = `${newPrefix}`
newFiles.push({url: file.url, filename: newName})
}
// Reattach the item with the new filename
await table.updateRecordAsync(record, {
"ATTACHMENT": newFiles
})
Firstly
The above script actually worked for 2 or more files and has been working, but unfortunately calls both files the same name… so ideally I could add a “+1” to it at some point…
Secondly, it actually deleted 2 files (BIG PROBLEM) today when uploading after using the script 100 times without problems… So I’m a little stumped. Perhaps you know why?
Lastly, it always says… but still works
TypeError: files is not iterable
at main on line 13
I’m curious about your thoughts.
Best,
Cam
Hey Jonathan,
Thanks for adding some color context on this. I missed your notification initially until now, so sorry for the delay.
So, sorry if I didn’t explain the use case correctly.
TLDR: file names of imported files are imported like this:

The files are DOCX or PDF, so we rename to PDF they always work.
Anyways, to your question above, we actually generally have multiple files about 50% of the time. I gave it my best shot this week (Before I got your notification) to edit the the scprit:
// Setup
let config = input.config()
let table = base.getTable("TABLE1")
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 newName = `${newPrefix}`
newFiles.push({url: file.url, filename: newName})
}
// Reattach the item with the new filename
await table.updateRecordAsync(record, {
"ATTACHMENT": newFiles
})
Firstly
The above script actually worked for 2 or more files and has been working, but unfortunately calls both files the same name… so ideally I could add a “+1” to it at some point…
Secondly, it actually deleted 2 files (BIG PROBLEM) today when uploading after using the script 100 times without problems… So I’m a little stumped. Perhaps you know why?
Lastly, it always says… but still works
TypeError: files is not iterable
at main on line 13
I’m curious about your thoughts.
Best,
Cam
just a bit more context, this is what normally happens:

this is what happened and it’s super concerning:

and what is strange is the file is correct on the one that was removed… anyways, throwing a lot of extra info so you (or anyone) has context.