Iconnek documentation
  • Quickstart
    • Introduction
    • Quick start guide
  • Configure
    • Connectors
    • Webhooks
    • Filter Lists
    • Conversion Tables
  • Using iconnek
    • Using the Iconnek Editor
      • Scenarios
      • Nodes
      • Data supervision
        • Dashboard
        • Terminal
        • Context Viewer
    • The Nodes
      • Comment
      • Exception
      • Function
      • Switch
      • Fan Out
      • Sequencer
      • Connector
      • Filter
      • Conversion
      • Mail
      • Catch
    • Using the Function node
    • Working with messages
    • Using global variables
    • Error handling
  • Deploying iconnek
    • Scheduling
    • Deployment
  • Ressources
    • How-to integrates
      • ConnectWise
      • Folks API V2
      • Genius ERP
      • Hector
      • Jovaco
      • Open AI
      • NetSuite
      • Microsoft Dynamics 365 Business Central
      • Zoho Books
      • Zoho CRM
  • Billing
    • Usage
  • PARTNERS
    • Partners
  • Security
    • Security
    • Service Level Agreement
  • Support
    • Contacting Support
Propulsé par GitBook
Sur cette page
  • Writing a Function
  • Working with the object msg
  • API Reference
  1. Using iconnek

Using the Function node

The Function node allows JavaScript code to be run against the messages that are passed through it.

The message is passed in as an object called msg. By convention it will have a msg.payload property containing the body of the message.

Other nodes may attach their own properties to the message, and they should be described in their documentation.

Javascript full support ECMAScript 6.0

Writing a Function

The code entered into the Function node represents the body of the function. The most simple function simply returns the message exactly as-is:

;

The returned message object does not need to be the same as was passed in; the function can construct a completely new object before returning it. For example:

msg.payload = { payload: msg.payload.length };

Working with the object msg

Accessing Payload

The msg.payload property holds the main data of the message. It can be of any data type: string, number, object, array, etc. You can access it directly or manipulate it using JavaScript functions or other nodes in your flow.

// Accessing payload
const data = msg.payload;

Setting Payload

You can set the payload of the msg object using the msg.payload property.

// Setting payload
msg.payload = "Hello, world!";

Conditional Execution

You can use the properties of the msg object to make decisions in your flow. For example, you might check the payload type or value to determine which path the flow should take.

// Conditional execution based on payload
if (msg.payload > 50) {
    // Do something
} else {
    // Do something else
}

The Function node should modify the received message rather than creating a new one. When constructing a new message object, all existing properties from the original message are lost, which can break downstream processes. For example, the Connector node specifically requires msg.payload properties to function correctly.

Best Practice: Function nodes should always return the original message object after making necessary modifications to its properties. This preserves all essential metadata and ensures compatibility with all nodes in your workflow.


API Reference

The following objects are available within the Function node.

Node

  • msg.logs(..) : get logs from a node

  • msg.payload(..) : main body message

  • msg.params(..) : define request parameters for the following connection node

  • msg.route_params(..) : define path reference parameters for the following connector node

  • msg.query(..) : query string for the special node

Global Variables

  • vars.{variableName}(..) : set data context in variable

PrécédentCatchSuivantWorking with messages

Dernière mise à jour il y a 3 mois