Jun 09, 2023 12:06 AM
Hi guys!
Can anyone help with modifying a script bellow so it forks with automations when a new record is created?
Currently, the script works when a button is pressed. The script extension is activated and attachments are resized.
The script :
Jun 09, 2023 07:48 AM - edited Jun 09, 2023 07:55 AM
Hi,
At first, remoteFetchAsync won't work in automation, try to use 'fetch'. in button script at first.
then, hardcode upper 4 variables on the left side of automation code editor, put names and values
and add fifth, 'id' with '+' add trigger record ID in value
then
let {tinyPngApiKey, airtableAttachmentSource, airtableAttachmentDestination, airtableColumnToLog, id}=input.config()
I would suggest shorter names, like fileSource, fileDestination etc..., but that's up to you
let table = base.getTable('baseName');
let record=await table.SelectRecordAsync(id)
note: ..RecordAsync.. , not RecordsAsync, you need just one record
other part of script should work as is
if 'fetch' fails in button script, there is a chance it might work in automation.
p.s. automation run limit is 30s. with fetching each file in a loop, I think, it can't process more than 5(?) files in a cell. it depends on several factors and you can evaluate the time running from button. Automation usually work slower than script.
Jun 12, 2023 05:57 AM
Hi Alexey,
I will give it a try and get back with results. Thanks for reaching out 👍
Jun 13, 2023 01:38 AM
Alexey,
I've managed to get script working but, like you said, when exceeding automation run limit of 30s automation fails.
Is there a way around it?
Jun 13, 2023 08:50 PM
It depends on different 'how much'-es.
how much files usually in a cell, how much time it takes for 1 file, 3 or 5 files
if you have enough automation runs, you could add image process field (array of URLs in text form, comma separated),, second automation should read cell, split to array, pop last/first value, write the rest back to field, process taken element.
with 'write blank, then write value' you can use process field with 'matches conditions' (= non empty) trigger
so, it will shrink one by one.
Also search tinify API for batch file shrinks - if present, it could be other option. I did a quick look and find nothing