JS: Chaining multiple actions together

I’ve been using iCloud to store small javascript snippets in iCloud which really sped up development because I could quickly bring subroutines together into one longer action script using “require”. [E.g. to get credentials for an application]

However, I’ve now had iCloud disabled on my work iPad so this is no longer a possibility. I’ve moved some of my small js files into small action steps. I can make my old scripts work by putting these into a single action using “Include Action”. But, it’s quite clunky to do it. I looked at chaining together actions using “app.queueAction” but this doesn’t seem to work for multiple action steps.

Is there a scripting way to bring in code from multiple action steps, to avoid having to use the “Include Action” step?


There are a number of things you could do, probably easiest is to store your scripts in drafts. The below would be the equivalent of require, but loading from a draft with a known UUID:

let d = Draft.find(“UUID-TO-DRAFT”);

You could also read them from Dropbox or other scriptable file provider - but that would require they be loaded from the network every time.

Thanks for the speedy response.

I did think about using “eval” but because I can’t sync from iCloud to my iPad (my work have blocked the syncing) that would be tricky because of different UUIDs between different devices and also having to keep the drafts sync-ed.

What I’ve gone for is to put all of the java snippets in a single action as functions which I bring in using an “Include Action”. My main script then calls the functions.

I’m not totally sure what I’m doing, but it seems to work. Possibly a bit memory inefficient to bring in functions that I don’t need for the specific action, but for the limited actions I’m running it doesn’t seem to matter.

BTW - really impressed how easy it is to copy action groups over to my iPad using AirDrop.

I’ve posted an example of how this works in the Action Directory:

All this does is create a new card in Trello. It has a couple of functions which get the drafts content, or if the draft is empty, prompt the user. And then some Trello functions that go through the separate steps of creating a new note in Trello.

This shows how quick it can be to write a new action by calling the functions I’ve included - these same functions will be used in many different actions. Over time it means any improvement to an individual function is available to all the actions that use that function.

You could workaround this by querying for the draft in other ways using Draft.query (unique tag, or string in a comment, etc.).