Welcome to the community, @Cameron_Goldberg! :grinning_face_with_big_eyes: While attachments can be manually renamed, Airtable’s scripting options—in the Scripting app, or in the scripting action in an automation—only allow you to set the filename when first adding an attachment with a script. There’s no option for changing the filename of an existing attachment.
That said, you could use a process similar to what @ScottWorld described: collect the current URL of the attachment, then submit that as a new attachment in the same field with the name you want to use. I just ran a test using an automation, and it works surprisingly well. (NOTE: this will only work for a single attachment, which sounds like it’ll work for your use case; if anyone needs multiple attachments renamed, the setup will require some more detailed tweaking which I don’t have time to explore at the moment.)
I made a new automation using the “When record matches conditions” trigger, with the condition being that the attachment field is not empty. The scripting action requires four input variables from the triggering record:
- recordID - The record ID
- filename - The filename property of the attachment field
- fileURL - The URL property of the attachment field
- newName - The new name that you wish to assign to the attachment
The code for the scripting action step is below. This finds the existing file extension for the attachment and uses that for the new name, so your new name formula should not include the extension. That way it doesn’t matter what file type someone attaches (.gif, .jpg, .pdf, etc) because the script just uses the current extension, and only changes the rest of the name.
// Setup
let config = input.config()
let table = base.getTable("Table Name")
// Get the extension and add it to the new name.
let parts = config.filename 0].split(".")
let ext = parts parts.length - 1]
let newName = `${config.newName}.${ext}`
// Reattach the item with the new filename
await table.updateRecordAsync(config.recordID, {
"Attachment Field Name": m{url: config.fileURLr0], filename: newName}]
})