In the Automation Studio, you can execute your own javascript functions using the 'function' nodes. If you are familiar with this javascript function, you can manipulate the property directly.
The message is passed on 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.
Writing a Function
The code entered into the Function node represents the body of the function. If the function returns null, then no message is passed on and the flow ends. The function must always return a msg object. Returning a number or string will result in an error.
Example
The 'Function' node routes a message based on the timestamp seconds. Odd numbered seconds message goes to port 1 and even numbered seconds message goes to port 2.
Logging events
If a node needs to log something to the console, it can use one of the following functions:
node.log("Something happened");
node.warn("Something happened you should know about");
node.error("Oh no, something bad happened");
The warn and error messages also get sent to the flow editor debug tab.
Storing data
Aside from the msg object, the function node can also store data into the context store.
In the Function node there are three predefined variables that can be used to access the context:
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.