Get Data By Index
Get Data By Index picks one item from a list by its position. It is useful, for example, to keep the first result of a search, the last message in a conversation or the third line of an order.
Positions start at 0: the first item is 0, the second is 1, and so on. You can also count from the end with negative numbers: -1 is the last one, -2 the one before it.
When to use it
- Keep the most relevant result of a search, which is usually the first one.
- Take the most recent order from a list sorted by date.
- Read the last message received in a conversation.
- From a list of customers, each with their invoices, take each customer’s first invoice.
Configuration
| Field | What it does |
|---|---|
| Data | The list you want to take an item from. |
| Index | The item’s position. Default: 0, the first one. Use -1 for the last one. |
Advanced options
| Field | What it does |
|---|---|
| Key | Use it when the list is not the one that arrives directly but sits inside each item. Enter the name of the field that holds it; if it is inside another field, separate them with a dot, for example order.lines. The component looks for that field in each item and keeps the position set in Index. If you leave it empty, the position applies to the list that reaches Data. |
Output
The Data output returns:
- Without Key: the list item at the chosen position.
- With Key: what sits at that position inside the field you named. If several items arrive, you get a list with one result per item.
If what sits at that position is a plain value, such as a text or a number, it comes in the value field, for example {"value": 30}.
If the position does not exist, for example you ask for the fifth item in a list of three, the result comes back empty.
Example
A sales team searches a business directory and only wants to work with the first result.
- Connect the list of search results to Data.
- Leave Index at 0.
- Connect the Data output to the component that adds the company to the CRM.
Related components
- Slice Data: to keep several consecutive items from a list.
- Get Value By Key: to read a specific field of an item.