Hello community!
This is my first Airtable script. I’ve been proud so far but there’s a detail that I cannot crack.
The situation is: I’m generating a dynamic chart via quickcharts.io using Airtable fields and I want to create a .png file from it to send by email.
So I created a formula field that generates the appropriate URL for the chart, this works perfectly.
Then, I created a script that runs upon that URL being updated, here’s the kink.
The script is based on a similar Airtable script which takes a URL and creates a file in another column on the same table.
The issue is that the ´filename´ is not being updated. It creates the file perfectly, but the filename is taken as a part of the URL which is unreadable and doesn’t contain the file extension.
Here’s my take:
let table = base.getTable("Table 5");
let attachmentField = table.getField("Attachments")
let inVar = input.config();
let url = inVar.Attachment_URL;
let updates = [];
let attachmentUrl = [{url: url, filename: 'Chart.png'}]; //does NOT change filename
updates.push({
id: inVar.Record_ID,
fields: {
"Attachments": [
...attachmentUrl,
],
},
});
await table.updateRecordsAsync(updates);
console.log(attachmentUrl);
console.log(updates);
//Check filename
let recordsAll = await table.selectRecordsAsync({ fields: [attachmentField] });
let record = recordsAll.getRecord(inVar.Record_ID);
console.log(record.getCellValue("Attachments")[0]);
My issue might sound silly (and I hope it has a simple solution), but it’s very important; the users will receive the file by email, so the current name is extremely sketchy. I’d like them to trust the file they receive (they will be expecting one!)
Here’s a sample picture:
Any help or idea in getting the filename right is greatly appreciated!
------UPDATE------
If I delete the URL and paste it again in the field, sometimes the filename is changed correctly (see picture).
So I think the script itself is not the problem. Still, this is not a consistent behaviour and it would be great if the filename was always the correct one.