Sep 19, 2022 09:37 PM
Hi everyone, I have a bunch of records and have used the QR Code Generator extension to generate a QR Code and save it to an attachment field. The problem with this is that each QR code has the same filename (as there’s no option to rename the file), this makes it very confusing when downloading them all.
I have come across a script here : Automate changing the file name of an attachment
// Setup
let config = input.config()
let table = base.getTable(“ :amphora: CONSIGNED ITEMS”)
let query = await table.selectRecordsAsync()
let record = query.getRecord(config.recordID)// Collect record data
let newPrefix = record.getCellValue(“AuctionLotNumber”)
let files = record.getCellValue(“Bidsquare Cloud QR”)// 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, {
“Renamed Bidsquare Cloud QR”: newFiles
})
However, I’m struggling to implement that solution (and couldn’t figure out how to restart or reopen that other topic). I am getting errors at:
let config = input.config()
let query = await table.selectRecordsAsync()
What I am trying to do is rename each QR Code using information from another field (called ‘AuctionLotNumber’ in the same Table ( :amphora: CONSIGNED ITEMS).
Thanks in advance for the help!
Sep 20, 2022 09:29 PM
Thanks for the clarification (and sorry for not checking on that earlier). For future reference, that detail would have been helpful to know up front. Airtable’s two scripting environments—the Scripting extension and the “Run a script” automation action—are very similar, but there are important differences that can make a script written for one not work in the other, especially when it comes to the input
mechanism.
I’m afraid that I’m short on time right now or else I’d go into the changes that @kuovonne mentioned. If anyone else is able to cover them, please do.
Sep 20, 2022 09:41 PM
Oh right, sorry I didn’t even know that there were 2 different environments. I will give it a try in the Run a Script automation action. Thank you.
Sep 20, 2022 10:39 PM
I have tried to use an automation to run a script, but I am now getting an error on : let record = query.getRecord(config.recordID)
Thanks.
Sep 21, 2022 05:51 AM
Did you create the input variable named recordID
in the left side of the editor and set the value to the record id of the triggering record?
Sep 21, 2022 06:29 AM
No I did not :grimacing:
Thanks a lot! It works 😃
Jan 09, 2023 02:58 AM
Hello @Kevin_Parmar
I have the same problem, can you share the script that runs correctly in automation ?
Thanks in advance.
Thierry
Jan 09, 2023 07:35 AM
Hi, the one I posted above worked. I just hadn't set the input variable as recordID and value = Airtable record ID. Hope that helps.
Aug 24, 2023 11:21 AM
Hello, all! I am trying to achieve something similar with my base in the automations side of scripting. When a user marks a field as true (checkbox) and the employee ID field has a value, I want to rename the attachment field in that same record to the entered the employee ID# entered. I have the triggered action set in the automation, but am having a hard time with the scripting. Any advice for someone whose scripting is rustier than she remembered?