Skip to content
Docs
Modules Constructor

Your own code

The Code Execution module in the Multogram Modules Constructor: built-in JavaScript, Python, Node.js, CMD, Bash and PowerShell. How variables and resources are inserted, how to return a result, packages.

If a ready-made action isn't enough, write a piece of code — the Code Execution module runs it right in the scenario.

Languages

ActionLanguageWhen to choose it
Execute JavaScript (ECMA)Built-in JavaScriptCalculations and data processing. Nothing to install; no require, Node.js modules or asynchrony
Execute PythonPythonPython libraries, complex processing
Execute Node.jsNode.jsnpm packages, familiar JavaScript
Execute CMD, Execute PowerShell, Execute BashCommand shellsSystem commands and scripts

Packages are installed with the Install Python Package and Install Node.js Package actions and removed with the matching actions. Python and Node.js must be installed on the module user's computer; the built-in JavaScript needs nothing — choose it for modules you hand out.

Variables and resources in code

Before running, [[variables]] and {{resources}} are inserted into the code according to where they are:

Where the reference isWhat is insertedExample
In the codeA value of its own type: text in quotes, a number, an objectvar n = [[count]]; → var n = 5;
Inside a quoted stringJust text, without extra quotesprint("phone=[[phone]]") → print("phone=79000000000")

Write [[x]] right in the code to get the value; put it in quotes only if you need it as text. References in comments are not inserted.

A typo in a name won't cause an error

A non-existent variable turns into null (in Python — None), and execution continues. If the result is odd, check the names first.

How to return a result

  • The program's output (print(...), console.log(...)) goes into the action's result variable.
  • An assignment [[name]] = value right in the code creates or changes a scenario variable — objects and arrays are saved as they are. Works in Python, Node.js and the built-in JavaScript.
Execute JavaScript (ECMA)
var digits = ('' + [[phoneInput]]).replace(/[^0-9]/g, '');
[[phone]] = { ok: digits !== '', value: digits };
print(digits ? '+' + digits : 'EMPTY');

After this action the scenario has a [[phone]] object with the ok and value fields, and the result variable holds the printed string.

When you don't need code

A lot is already available as ready-made actions: strings, JSON, regular expressions, math, date and time — see Modules and actions. Ready-made actions are easier to read and check; leave code for what they can't express.

Updated

CookiesPrivacy Policy

We use essential cookies to run this site. With your consent, we will also use analytics cookies to improve it and marketing cookies to credit whoever referred you. You can change your choice at any time.