Building Your First n8n Workflow!
1. Building Your First n8n Workflow!
Great work so far! Now you can trigger workflows, let's actually make them do something!2. Data in n8n
Data in n8n is stored as an array of items, which move like boxes on a conveyor belt through the workflow. Each item has fields — like email — and values assigned to it, which are like the label and contents of each box on the conveyor belt.3. Data in n8n
These fields are stored as JSON, which is a universal file type used in software engineering. Each field name is linked to its value using a colon in the JSON. This universal data structure means n8n workflows can be easily hooked-up to existing systems. Given the importance of data in n8n workflows, our first workflow will create and edit some data once triggered.4. New Node: Edit Fields
To do this, we'll be using the Edit Fields node. This node can be used to set and override workflow data. Keeping with our conveyor belt analogy, the edit fields node is like a robotic arm that can add, change, or remove boxes from the belt. And like a robotic arm would use labels and bar codes to make these changes, this node uses field names. Commonly the edit fields node is used for filtering fields to remove unnecessary information, and for performing calculations to create new fields.5. Example: Adding and Transforming Data
Let's start by creating a workflow that creates some data, then filters it. This workflow uses a manual trigger, which recall, activates the next node along. Here's where we add our first Edit Fields node. Clicking into the interface, we can define our field names, their type, and a value. Here, we'll create a name field, which is set to the string type as it contains text, and then we give it an example name as a value. Underneath, we'll create an email field with the string type and an example value. To see the results, we execute the step and can see that it creates the data we requested in JSON structure. If you're not a fan of JSON, you can use the schema or table views to get something more familiar. Let's say that downstream of this node, we only need the email field for our analysis. We can add a second Edit Fields node connected to the first one. If we click into this new node, we can already see the data outputted by the first node in the input section. To select only the email column, we can drag and drop the column name from the schema view of the input section into the center section. Underneath the field's data types, we can see some JSON was automatically created. This is called an expression, and it links the input data to the desired output. Dragging and dropping means we don't need to write these expressions ourselves. Executing the step, we can see in the output section that only the email field was outputted. Back in the canvas, we can see a second workflow. It's possible to work with multiple workflows in the same canvas, but we need to execute the trigger nodes separately, or deactivate one to be able to use the execute workflow button, which is what we do here.6. Example: Transforming Form Data
In the second workflow, we have a form trigger that has already been populated with several fields. We'll execute this and add an example person so there's some data already flowing through it - this will also mean we can drag-and-drop fields when adding downstream nodes. This time, instead of removing fields, we'll add a new one that records when the data was received by the workflow. To do this, we'll add a new Edit Fields node connected to the form trigger. Inside, we drag the key input fields into the center section to persist them. For our new field, called "received at", we're actually going to write a simple expression to capture the current datetime. If we hover around our new field, we can toggle on expression mode. Here, if we write dollar-now inside double curly brackets, this expression will automatically add the current datetime to the data when triggered. dollar-now is one of a number of special built-in methods for when we want to perform common functions as expressions. Executing our node, we can now see the timestamp alongside the user's input information.7. Let's practice!
Time for you to build your first n8n workflows from scratch!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.