Dec 02, 202208:29 AM - edited Dec 02, 202208:30 AM
I added extension "Create records for multiple templates". I hooked it up to run when a button is pressed. It is working correctly.
But I would prefer for it to run auto once conditions are met. I know this can be done in automations with a scripting block. My question is - can I just copy and paste code from the extension into a scripting block for automation?
I tried, but I am seeing a lot of red. I assume I am misunderstanding the foundation of the code, or I am missing a step? Would adding something in the input variables to make this work?
Generally speaking, moving a script from a Scripting Extension to a Run a Script action within an automation is rarely a simple copy and paste.
The Scripting Extension has several input and output commands designed to ask a user a question or show a user something. Since the Run a Script action is autonomous, there is no need for the vast majority of those inputs/outputs and therefore none of them will work.
Rules of thumb when moving from the Scripting Extension to the Run a Script action step:
Any line that includes `input.something` needs to be replaced with either a hardcoded value, or an input variable. For instance, you likely would replace an `await input.recordAsync()` with an input variable that pulls in whatever record fired the automation.
`input.config()` works in both Extensions and Automations but the function expects very different values depending on which environment you're using. See API reference. The API will tell you what functions work in Extensions, which work in Automations, and which work in both.
There are no settings for an automation script. Replace each of your settings by simply declaring each variable. For example, tables would look something like `const parentTable = base.getTable("Name or ID of table")`. Refer to the Script API for declaring tables and for declaring views and fields.
Any line that includes `output.something` can be deleted. There is no "place" to output anything in an automation script.
If you have specific questions about a specific script, its best to give a link to that script since very few of us here in the forums have every published script memorized or bookmarked.