Nov 27, 2023 05:30 PM
Hey community, Aundre here. I hope you're all doing well!
I found this script on YouTube that works once you're on any table view where applicable. I need to automate it to work without being on a specific view. When I run it from automations, it does not work, I get the error below.
The automation I am trying to create is to run whenever a record enters a view. It should run the script which compresses images in the IMAGE column via TinyPNG, and then output them in IMAGE COMPRESSION. However, I find that I have to be on the view itself, click 'run script' for it to work. The automation however is not running from a view standpoint, hence why I believe it's giving an error.
After the image has been compressed, I'd like the IMAGE column to clear (delete) the original image, leaving only the compressed one. I've been able to do a simple automation for this by making the action an Update record and leaving the IMAGE field blank. However, I need it to be in one where it will clear the original image after the script runs. I'd allow a 20 second delay before clearing the original image, just to ensure that the image(s) upload(s) to TinyPNG.
I'm hoping this can work! Thank you community!
The errors:
The YouTube video:
https://www.youtube.com/watch?v=OAXm5-gqBT8
The script:
Solved! Go to Solution.
Nov 29, 2023 06:52 PM - edited Nov 29, 2023 06:54 PM
Hey Sho, I used ChatGPT to fix the btoa error and it worked! When I first started off, it gave me errors and I just copied and pasted the errors and kept trying. I was about to give up and move on, and then I pasted the last error and it seemed as though ChatGPT was getting frustrated on its own and wrote me a very long code which just happened to work! 😅 See the code below! I just want to say thank you once again! You started me off, which really narrowed down the issues to this solution! 5-stars Sho!
Nov 27, 2023 05:58 PM
Hi @aundre_hamilton,
Unfortunately, this script is for extensions and does not work with automation.
How about trying it by specifying the table name and view name directly?
let table = base.getTable("Table Name");
let view = table.getView("View Name");
Nov 27, 2023 06:15 PM
Thank you Sho! No more errors there! Now it's at line 23, saying that 'remoteFetchAsync is not defined'. What do you suggest here?
let request = await remoteFetchAsync('https://api.tinify.com/shrink', {
Nov 27, 2023 06:25 PM - edited Nov 27, 2023 06:26 PM
Yes, there is no remoteFetchAsync function in the script action.
How about this.
let request = await fetch('https://api.tinify.com/shrink', {
Nov 27, 2023 06:32 PM
No more errors there! I hope this next one is the last one. I realized that wherever there is an error, even before running the script, it has a red wrinkled underline. It's similar to spelling a word incorrectly or having a grammatical error. So, now 'btoa is not defined'.
Authorization: 'Basic ' + btoa('api:' + tinyPngApiKey),
Any solutions here?
Nov 27, 2023 07:52 PM
Here is the solution.
It looks like you need to get the value from the extension once.
Nov 29, 2023 06:52 PM - edited Nov 29, 2023 06:54 PM
Hey Sho, I used ChatGPT to fix the btoa error and it worked! When I first started off, it gave me errors and I just copied and pasted the errors and kept trying. I was about to give up and move on, and then I pasted the last error and it seemed as though ChatGPT was getting frustrated on its own and wrote me a very long code which just happened to work! 😅 See the code below! I just want to say thank you once again! You started me off, which really narrowed down the issues to this solution! 5-stars Sho!
Nov 29, 2023 07:43 PM
That is indeed ChatGPT, btoa implemented!
You maybe could have asked this.
convert the following with the javascript btoa function. api:xxx
Nov 30, 2023 03:10 AM
The thing is, I am not a programmer at all. I am just good at Excel type formulas. So, turning to ChatGPT was just me taking a chance and if it didn't work, I'd have left it. 😅