How to include multiple records in the body of the email

Hi,

I managed to do as the image below, but I’m limited to 5 records, how can I bring how many records there are?

this is my workflow

{
  "name": "Email com lista registros",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        460,
        20
      ],
      "disabled": true
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1160,
        460
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"status\"]}}",
              "value2": "=TRUE"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        920,
        340
      ]
    },
    {
      "parameters": {
        "operation": "sort",
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "valor",
              "order": "descending"
            }
          ]
        },
        "options": {}
      },
      "name": "Ordem decrescente",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        1160,
        220
      ]
    },
    {
      "parameters": {
        "functionCode": " return [\n  {\n    json: {\n      data_object: items.map(item => item.json)\n    }\n  }\n]\n\n"
      },
      "name": "Transforma objeto único ",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1400,
        220
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "sheetId": "1LCgmRDuU22AGJ0GpIfm9Su8F9S1IL_bvi4xEPBtqqjY",
        "options": {
          "valueRenderMode": "FORMATTED_VALUE"
        }
      },
      "name": "Ler planilha",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        700,
        340
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "9",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 8
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        460,
        340
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "subject": "=Registros de {{$json[\"data_object\"][0][\"Vencimento\"]}}",
        "message": "=Ola\n\nVoce tem {{$json[\"data_object\"].length}} contas vencendo hoje\n\n{{$json[\"data_object\"][0][\"descrição\"]+ (': ')}} {{$json[\"data_object\"][0][\"valor\"]}}\n{{$json[\"data_object\"][1][\"descrição\"]+ (': ')}} {{$json[\"data_object\"][1][\"valor\"]}}\n{{$json[\"data_object\"][2][\"descrição\"]+ (': ')}} {{$json[\"data_object\"][2][\"valor\"]}}\n{{$json[\"data_object\"][3][\"descrição\"]+ (': ')}} {{$json[\"data_object\"][3][\"valor\"]}}\n{{$json[\"data_object\"][4][\"descrição\"]+ (': ')}} {{$json[\"data_object\"][4][\"valor\"]}}\n\nVamos automatizar",
        "toList": [
          "[email protected]"
        ],
        "additionalFields": {}
      },
      "name": "Enviar email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 1,
      "position": [
        1640,
        220
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "10",
          "name": "Gmail account"
        }
      }
    }
  ],
  "connections": {
    "IF": {
      "main": [
        [
          {
            "node": "Ordem decrescente",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ordem decrescente": {
      "main": [
        [
          {
            "node": "Transforma objeto único ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transforma objeto único ": {
      "main": [
        [
          {
            "node": "Enviar email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ler planilha": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Ler planilha",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 12
}

Hi @RicardoE105,

Any tips on how to do this?

Thanks

You need to combine the data in the Function-Node like this (so the Node named currently in your flow “Transforma objeto único”):

 return [
  {
    json: {
      length: items.length,
      message: items.map(item => `${item.json.descrição}: ${item.json.valor}`).join('\n')
    }
  }
]

You can then use it in the Gmail-Node (“Enviar email”) with the following expression:

Ola

Voce tem {{$json.length}} contas vencendo hoje

{{$json.message}}

Vamos automatizar
1 Like

Hi @jan,

Perfect, that’s how much better.

Thanks a lot for the help

You are welcome. Have fun!

1 Like