Merge pull request #1014 from ultrabug/course-level-one

Update course level one documentation
This commit is contained in:
Deborah 2022-11-15 16:48:51 +00:00 committed by GitHub
commit 0507e76366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View File

@ -26,8 +26,6 @@ Now, in your Editor UI, add an *HTTP Request node* like you learned in the lesso
In the left panel, select:
- *URL:* The Dataset URL your received in the email when you signed up for this course.
- *Options > Add Option > Split Into Items:* toggle to true.<br/>
This option will output each element of an array as its own item.
- *Headers > Add Header:*
- *Name:* `unique_id`
- *Value:* The Unique ID your received in the email when you signed up for this course.

View File

@ -1,23 +1,23 @@
# 5. Calculating Booked Orders
In this step of the workflow you will learn how n8n data is structured and how to add custom JavaScript code to perform calculations using the *Function* node.
In this step of the workflow you will learn how n8n data is structured and how to add custom JavaScript code to perform calculations using the *Code* node.
The next step in Nathan's workflow is to calculate two values from the booked orders:
- The total number of booked orders
- The total value of all booked orders
To calculate data and add more functionality to your workflows you can use the **Function node**, which lets you write custom JavaScript code.
To calculate data and add more functionality to your workflows you can use the **Code node**, which lets you write custom JavaScript code.
!!! warning "Function vs Function Item"
n8n also provides a **Function Item node**, which should not be confused with the Function node. The Function Item node is used to add custom snippets of JavaScript code that should be executed once for every item that it receives as the input. Learn more about the difference between the Function and Function Item nodes [here](/data/code/){:target="_blank" .external}.
!!! warning "Code node modes"
The **Code node** has two operational *Modes* that change the way it processes data. The *Run Once for All Items* mode allows you to accumulate data from all items on the input list. The *Run Once for Each Item* is used to add custom snippets of JavaScript code that should be executed once for every item that it receives as the input. Learn more about the difference between the Function and Function Item nodes [here](/data/code/){:target="_blank" .external}.
Before going into the setup of the Function node, you should first learn the [data structure](/data/data-structure/){:target="_blank" .external} of n8n. This is important if you want to:
Before going into the setup of the Code node, you should first learn the [data structure](/data/data-structure/){:target="_blank" .external} of n8n. This is important if you want to:
- Create your own node.
- Write custom expressions.
- Use the Function or Function Item node.
- Use the Code node.
- Get the most out of n8n.
In n8n, the data that is passed between nodes is an array of objects with the following structure:
@ -51,9 +51,10 @@ In n8n, the data that is passed between nodes is an array of objects with the fo
Now let's see how to implement this.
In your workflow, add a *Function* node connected to the false branch of the *IF* node. In the *Function* node window paste the following code in the JavaScript Code box:
In your workflow, add a *Code* node connected to the false branch of the *IF* node. In the *Code* node window paste the following code in the JavaScript Code box:
```javascript
let items = $input.all();
let totalBooked = items.length;
let bookedSum = 0;
@ -72,11 +73,11 @@ Notice the format in which we return the results of the calculation:
Now execute the node and you should see the following results:
<figure><img src="/_images/courses/level-one/chapter-two/Function-node.png" alt="Function node" style="width:100%"><figcaption align = "center"><i>Function node</i></figcaption></figure>
<figure><img src="/_images/courses/level-one/chapter-two/Function-node.png" alt="Code node" style="width:100%"><figcaption align = "center"><i>Code node</i></figcaption></figure>
## What's next?
**Nathan 🙋**: Wow, the Function node is really powerful! So if I have some basic JavaScript skills I can power up my workflows.
**Nathan 🙋**: Wow, the Code node is really powerful! So if I have some basic JavaScript skills I can power up my workflows.
**You 👩‍🔧**: Exactly you can progress from no-code to low-code!

View File

@ -8,7 +8,7 @@ Now that you have a calculated summary of the booked orders, you need to notify
You can replace the Discord node with another communication app. For example, n8n also has nodes for [Slack](/integrations/builtin/app-nodes/n8n-nodes-base.slack/){:target="_blank" .external} and [Mattermost](/integrations/builtin/app-nodes/n8n-nodes-base.mattermost/){:target="_blank" .external}.
In your workflow, add a Discord node connected to the Function node. In the Discord node window, configure the parameters:
In your workflow, add a Discord node connected to the Code node. In the Discord node window, configure the parameters:
- *Webhook URL:* Enter the URL that you received in the email from n8n when you signed up for this course.
- *Text (Expression):* This week we have `{{$json["totalBooked"]}}` booked orders with a total value of `{{$json["bookedSum"]}}`. My Unique ID: `{{$node["HTTP Request"].parameter["headerParametersUi"]["parameter"][0]["value"]}}`