Jump to a Section
  • Code Functions

    Note: Check the Settings -> Subscription page to see whether or not your plan includes the use of Code Functions, and if so, what limits are in place.

    The Code Functions feature allows you to upload and optionally share JavaScript functions that can be called from Flows. (Additional languages may be supported in the future.)

    “Call Code Function” card

    You can find the “Call Code Function” card in the “Code” category when you click “Add Function” while working on a Flow. On step 1 ”Options” are two dropdowns:

    • code:  Click and select the code module you want to call. (If you haven’t yet uploaded your code, read the “Uploading, Managing and Sharing JavaScript Code Functions” section below.)
    • function:  After you’ve chosen the code, you can choose from the list of functions that are included in that code, and then click “Next” to advance to the next tab.

    On step 2 “Data” there are two sections for Inputs and Outputs. If the code declared “@param” and “@return” in the proper format in the comments (see details below), the names and types of the inputs and outputs for the function are provided. Otherwise, you have to create new fields that match the exact name and type that the function expects.

    Uploading, Managing and Sharing JavaScript Code Functions

    To access the Code Functions panel:

    1. Click Settings from the top navigation
    2. Click “Code Functions”

    You’ll see an “+Upload Code” button and the list of existing uploaded code that you have access to.

    To Upload new functions that can be called from Flows, click “+Upload Code” to bring up the “Upload Code” dialog. Provide a Name (required) and Description (optional).

    For simple projects with no dependencies, click Write Code to bring up a basic code window where you can paste in or compose a basic function set. The format (see example below) requires module.exports to reference an object that contains keys as function names and values as functions. All entry functions should conform to the same signature: _(req, res)_ where req is the incoming message and res is the server response.

    For more complex projects, where dependencies, or multiple files are required, code can be uploaded using Upload Code and providing a zip or tar.gz file. The format requires an index.js file at the root of the extracted archive with the same module.exports format as above. If a package.json is included, the dependencies listed will be installed. Other modules can be included and used within index.js.

    Here is an example of a single function:

    module.exports = {
     * @name Average
     * @param {number} Total
     * @param {number} Count
     * @return {number} Result
     Average(req, res) {
       var inputs = req.body.data;
       if (inputs.Count == 0) {
         res.status(500).send("Div by 0");
       else {
         var output = inputs.Total / inputs.Count;
         res.status(200).send({"Result": output});

    The optional comment block shown uses JSDoc format (one block per function) to specify the names and types of the input and output fields to automatically show up in the “Call Code Function” card; if not provided, users will have to manually provide the name and type of each input and output when they call the function. Types can be number, string, object, boolean, date or a list of any of those by adding square brackets after the type, e.g. “{number[]}” for a list of numbers.

    Once you’ve uploaded code, additional options are available by clicking the icons at the right side in the code list:

    • Edit:  Click the Pencil icon to edit code you’ve already uploaded
    • Manage Permissions:  Click the Person icon to share your code with other users. The sharing options are exactly the same as sharing application accounts, i.e. If you share a Flow that calls your code, other users will be able to run that Flow but will otherwise have no access to your code unless you grant them “Can Use” or “Can Edit” permission.
    • Status: A green check or red alert tells you whether the code successfully uploaded and is ready to run. You may see a spinner when you first upload or save edits. Click the red alert icon to get error details.
    • Delete: Click the Trash Can icon to remove code you’ve uploaded.

    Here’s another code sample:

    module.exports = {
      * @name MyFunction
      * @param {number} x
      * @param {number} y
      * @return {number} sum
      * @return {string} concat
      * @return {object} construct
      * @return {boolean} xIsMax
     MyFunction: function(req, res){
       var data = req.body.data;
         sum: data.x + data.y,
         concat: [data.x, data.y].join(""),
         construct: {
           x: data.x,
           y: data.y
         xIsMax: data.x >= data.y