After splitting out, how do I test the number of objects returned?

In my workflow, I have an array that runs through a split-out node. If everything is there, I get 26 objects and process them. If one or more objects don’t exist, I need to create them. The easiest way I can think of to test is to compare the number of objects to our desired number.

I can put in an if node, but how do I reference the number of objects returned from the Split-Out node?

Information on your n8n setup

  • n8n version 1.8.2
  • Default database
  • n8n running in Docker on Digital Ocean.
  • Running on Ubuntu 22.04.3 LTS

Hi @russellkg :wave: Would you be able to share your workflow so I can see a little bit more in depth about what you’re doing, and preferably with some sample data? That being said, you might be able to just use something like .length if the data you’re working with is an array :+1:

Here’s my workflow. I’m not sure how to include data other than paste it in here, raw. Please let me know of a better way.

Here are two records. The Custom Fields List node pulls them out. If there are not 26 fields, I need to know so I can populate missing fields. I really don’t want 26 if statements and a switch doesn’t seem to do a negative. :slight_smile:

{
    "assets": {
      "id": 4620,
      "company_id": 7,
      "asset_layout_id": 30,
      "slug": "tonyg-mba-m2-8fd09d8bf447",
      "name": "TonyG MBA M2",
      "primary_serial": "L9H4GK676V",
      "primary_mail": "",
      "primary_model": "MacBook Air (M2, 2022)",
      "primary_manufacturer": "Apple, Inc",
      "company_name": "A Company",
      "object_type": "Asset",
      "asset_type": "Computers",
      "archived": false,
      "url": "https://kginger.huducloud.com/a/tonyg-mba-m2-8fd09d8bf447",
      "created_at": "2023-06-09T17:30:19.745Z",
      "updated_at": "2023-10-04T23:39:01.184Z",
      "fields": [
        {
          "id": 26222,
          "value": "tony",
          "label": "Last User",
          "position": 1
        },
        {
          "id": 24879,
          "value": "L9H4GK676V",
          "label": "Serial Number",
          "position": 2
        },
        {
          "id": 26220,
          "value": "MacBook Air (M2, 2022)",
          "label": "Model",
          "position": 3
        },
        {
          "id": 26228,
          "value": "macOS 13.6",
          "label": "Operating System",
          "position": 4
        },
        {
          "id": 28041,
          "value": "10/4/2023",
          "label": "Last Mosyle Update",
          "position": 6
        },
        {
          "id": 26221,
          "value": "Apple, Inc",
          "label": "Manufacturer Name",
          "position": 7
        },
        {
          "id": 26223,
          "value": "192.168.17.217",
          "label": "Primary IP",
          "position": 9
        },
        {
          "id": 26226,
          "value": "8",
          "label": "Installed RAM",
          "position": 10
        },
        {
          "id": 26227,
          "value": "494.0000000000",
          "label": "Boot Volume Capacity",
          "position": 11
        },
        {
          "id": 26229,
          "value": "342.0000000000",
          "label": "Boot Volume Usage",
          "position": 12
        },
        {
          "id": 26225,
          "value": "a8:8f:d9:32:f4:ea",
          "label": "MAC Address",
          "position": 14
        },
        {
          "id": 26224,
          "value": "TonyG MBA M2",
          "label": "Name",
          "position": 26
        }
      ]
    },
    "rows": 26,
    "page_size": 50,
    "page": 1,
    "devices": {
      "total_disk": "494.0000000000",
      "device_name": "TonyG MBA M2",
      "serial_number": "L9H4GK676V",
      "tags": "hrcc,sso",
      "date_last_beat": "1696467165",
      "available_disk": "338.0000000000",
      "osversion": "14.0",
      "device_model_name": "MacBook Air (M2, 2022)"
    }
  },
  {
    "assets": {
      "id": 1460,
      "company_id": 7,
      "asset_layout_id": 30,
      "slug": "weborders-imac-499c02108777",
      "name": "Weborders iMac",
      "primary_serial": "C02YL0W1H7VF",
      "primary_mail": "",
      "primary_model": "iMac (21.5-inch, 2017)",
      "primary_manufacturer": "Apple, Inc",
      "company_name": "A Company",
      "object_type": "Asset",
      "asset_type": "Computers",
      "archived": false,
      "url": "https://kginger.huducloud.com/a/weborders-imac-499c02108777",
      "created_at": "2022-02-09T18:00:21.216Z",
      "updated_at": "2023-10-04T23:39:02.052Z",
      "fields": [
        {
          "id": 26232,
          "value": "weborders",
          "label": "Last User",
          "position": 1
        },
        {
          "id": 24899,
          "value": "C02YL0W1H7VF",
          "label": "Serial Number",
          "position": 2
        },
        {
          "id": 26230,
          "value": "iMac (21.5-inch, 2017)",
          "label": "Model",
          "position": 3
        },
        {
          "id": 26238,
          "value": "macOS 13.6",
          "label": "Operating System",
          "position": 4
        },
        {
          "id": 28042,
          "value": "10/4/2023",
          "label": "Last Mosyle Update",
          "position": 6
        },
        {
          "id": 26231,
          "value": "Apple, Inc",
          "label": "Manufacturer Name",
          "position": 7
        },
        {
          "id": 26233,
          "value": "192.168.17.181",
          "label": "Primary IP",
          "position": 9
        },
        {
          "id": 26236,
          "value": "16",
          "label": "Installed RAM",
          "position": 10
        },
        {
          "id": 26237,
          "value": "250.0000000000",
          "label": "Boot Volume Capacity",
          "position": 11
        },
        {
          "id": 26239,
          "value": "194.0000000000",
          "label": "Boot Volume Usage",
          "position": 12
        },
        {
          "id": 26235,
          "value": "38:f9:d3:10:63:78",
          "label": "MAC Address",
          "position": 14
        },
        {
          "id": 26234,
          "value": "Weborders iMac",
          "label": "Name",
          "position": 26
        }
      ]
    },
    "rows": 26,
    "page_size": 50,
    "page": 1,
    "devices": {
      "total_disk": "250.0000000000",
      "device_name": "Weborders iMac",
      "serial_number": "C02YL0W1H7VF",
      "tags": "hrcc",
      "date_last_beat": "1696465513",
      "available_disk": "194.0000000000",
      "osversion": "13.6",
      "device_model_name": "iMac (21.5-inch, 2017)"
    }
  }

I believe I’ve figured it out. The If node is like so:

Please let me know if there is a better way to do this.

Thanks!

-Russ

3 Likes

Hi @russellkg :wave: That looks like what I would have done :sweat_smile:

1 Like

Thanks for the confirmation!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.