Oct 15, 2020 05:39 AM
I have a task that requires itertools. but I am having no luck. is it possible to import from itertools? or any other library for that matter? thanks
Solved! Go to Solution.
Oct 15, 2020 07:52 AM
You cannot import libraries in Scripting app.
You can copy/paste in minified versions of libraries into your script if they are small enough and in a single file.
There are also creative ways of having the script itself get raw library files and use eval
.
Or you can write a custom app, which can import node modules.
Oct 15, 2020 07:52 AM
You cannot import libraries in Scripting app.
You can copy/paste in minified versions of libraries into your script if they are small enough and in a single file.
There are also creative ways of having the script itself get raw library files and use eval
.
Or you can write a custom app, which can import node modules.
Oct 15, 2020 08:58 AM
Oct 15, 2020 09:44 AM
I personally don’t like storing libraries in tables where users who don’t know any better can do unexpected things with them.
An alternative is to get the library from a cdn. This method is slightly better because base users can’t mess with the library. However, keep in mind that every time you use eval
you have to really trust the source.
This example gets the mathjs library from a cdn. It isn’t very useful since you can use use Math out of the box, but in theory it should work with other libraries.
Plus, it looks like you can’t use eval
in automation scripts.
await getMathJs()
async function getMathJs() {
const response = await fetch("https://cdnjs.cloudflare.com/ajax/libs/mathjs/7.5.1/math.min.js");
const minifiedLibrary= await response.text();
eval(minifiedLibrary)
}
let answer = math.round(math.e, 3)
output.inspect(answer)
answer = math.round(math.pi, 15)
output.inspect(answer)
Oct 15, 2020 11:06 AM
I have used eval() in the past without issue.
I doubt this would work in any case because eval() would likely trip over anything minified. Try …
eval('0 == 1')
Pretty sure it should work.
Oct 15, 2020 11:29 AM
eval
won’t work for me in an automation action script. I get an error saying that it is not defined.
Why wouldn’t eval()
work on something minified? Minified code is still valid code. The code that I posted works for me in scripting app.
Oct 15, 2020 11:31 AM
Good to know - so this is simply an issue with script actions I guess. That’s unfortunate - there should be no limitation on eval; importing libraries is a different animal.
Apr 11, 2023 08:11 AM
Hi kuovonne!
Thank you for this technique=)
I'm trying to use it to import some functions from a file I have stored in Github, but I get a "not defined" error when I call the functions in the Airtable script. Any idea why?
I've already checked the fetch is working fine and also tried with a simple example succesfully, but no luck with the complete set of functions.