Help

Re: Rename attachments using values from other field

3211 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Kevin_Parmar
5 - Automation Enthusiast
5 - Automation Enthusiast

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()

  • selectRecordsAsync is strikethrough

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!

17 Replies 17

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.

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.

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.

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?

No I did not :grimacing:

Thanks a lot! It works 😃

Hello @Kevin_Parmar 

I have the same problem, can you share the script that runs correctly in automation ?

Thanks in advance.

Thierry

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.

kerricrow13
4 - Data Explorer
4 - Data Explorer

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?