Skip to content
Talk to our solutions team

Promote a script into a flow

The script you have been iterating on, running in a flow, without a rewrite.

This is the payoff for developing on the CLI at all.

Without thisWith this
Prototype in one place, rewrite for automationThe same file, unchanged
Two behaviours to debug — the script, and the portOne
A fix in production has to be back-ported to test itRun the same file locally

kis script uses the same engine and calling convention as a flow’s script: task. That is a guarantee you can lean on, not a coincidence.

function main(region) {
const rows = data.query("orders", { region: region });
return { region: region, count: rows.length };
}

Developed with:

Terminal window
kis script run summarise.js west --debug
name: regional-summary
vars:
region: west
tasks:
- name: summarise
script:
language: javascript
file: ./summarise.js
args: ["{{region}}"]

The file is the same file. What was a positional argument on the command line is args here.

Flags are not part of the script, so anything you set on the command line has to be declared in the task:

CLI flagIn the flow
positional args, --argsargs:
--func handlerfunction: handler
--namespaces log,httpThe task’s namespace configuration
--timeout 50The task’s timeout
--vars name=xFlow vars:, interpolated into args

--namespaces is the one to get right. A script you developed with all and deploy without restriction is unrestricted in the place it matters — see Restrict what a script can reach.

Promoting does not mean giving up the CLI. Reproduce a failing flow task locally with the same arguments:

Terminal window
kis script run summarise.js west --debug --namespaces log,db,json

Match the namespaces the flow grants and you are reproducing the flow’s conditions, not approximating them.

The script: task takes the body one of two ways, and one of them is a dead end for everything else in this section.

FormUse when
file:The script is more than a few lines, or you want to run it with kis script
code:It is short and only meaningful in that flow

Prefer file: for anything you will iterate on. A body inlined with code: cannot be run, validated or benchmarked with the CLI — it is not a file, so there is nothing to point the CLI at.

Run the flow with --dryrun first, then for real, and compare the task’s result with what the CLI produced for the same arguments. They should be identical — if they are not, the difference is in the flags, not the script.