Skip to content

Running one script from another

mash.scripts lets a script start another saved script. Use it to keep one well-tested routine (filing, logging, notifying) and call it from several automations.

There are three calls. All three take the script’s name or id, and optional file, user and input arguments.

CallWhat it does
mash.scripts.run(script, file, user, input)runs the child now, prints its output into yours, and returns what it returned
mash.scripts.import(script, file, user, input)runs the child now and returns what it returned, without printing its output
mash.scripts.queue(script, file, user, input, delay)puts the child on the queue and returns at once, with a job you can watch

run and import wait for the child. If the child ends with an error, the call throws, with the child’s script name and message. queue doesn’t wait, and an error in the child shows only on the run log.

# Parent: file the document, then ask a shared script to log it.
doc = mash.event.file
if not doc
return
end
result = mash.scripts.import("Log to the claims CSV", doc, null, {"stage": "filed"})
printline "Logged: {{result}}"

The child sees the input as mash.event.input, and the file as mash.event.file:

doc = mash.event.file
stage = mash.event.input["stage"] ?? "unknown"
return "{{doc.name}} at stage {{stage}}"
  • The clock. A child shares its parent’s deadline. Running a second script never buys more time. The tighter of the two limits applies.
  • Memory. The child gets at least what its parent had.
  • Variables. Not shared. Pass values in through input and take them out through the return value.
  • Settings. The child uses its own script settings, not the parent’s.
  • Permissions. A child never has more rights than its parent. See below.

A child runs as its own owner. If the parent is running under an ordinary user’s rights (not an administrator’s), these limits apply:

  • the parent can reach only scripts its own owner owns. Calling someone else’s script is refused with this automation can reach only its owner's own scripts;
  • a child written by an administrator still runs with the parent’s limits, never above them;
  • queue can’t name another person in user. Only the owner is allowed.

If the parent is an administrator’s script, it can call any script.

queue counts against the bulk-action caps on the Limits page: 100 queued jobs per run, and a shared allowance for the whole organisation. A script set to run only one copy at a time (MASH_SINGLE_INSTANCE) refuses to queue itself again while one is already running, with An instance of <name> is already queued or running.

The Scripts library page lists every method.