Merging 2 or more arrays

I am quite sure this is an FAQ, but a bit hard for me to search (which search terms?):

in my project with Zammad I get one array “Ticket” describing the ticket, and another one “articles” containing the individual articles the ticket contains of.

Ticket:

[
  {
    "id": 53,
    "group_id": 2,
    "priority_id": 2,
    "state_id": 2,
    "organization_id": null,
    "number": "740534",
    "title": "Testanfrage Weichinger",
    "owner_id": 3,
    "customer_id": 3,
    "note": null,
    "first_response_at": "2022-11-15T07:19:04.078Z",
    "first_response_escalation_at": null,
    "first_response_in_min": 0,
    "first_response_diff_in_min": 4320,
    "close_at": null,
    "close_escalation_at": null,
    "close_in_min": null,
    "close_diff_in_min": null,
    "update_escalation_at": null,
    "update_in_min": null,
    "update_diff_in_min": null,
    "last_contact_at": "2022-11-15T07:20:05.013Z",
    "last_contact_agent_at": "2022-11-15T07:19:41.008Z",
    "last_contact_customer_at": "2022-11-15T07:20:05.013Z",
    "last_owner_update_at": "2022-11-15T12:08:48.875Z",
    "create_article_type_id": 1,
    "create_article_sender_id": 1,
    "article_count": 33,
    "escalation_at": null,
    "pending_time": null,
    "type": null,
    "time_unit": null,
    "preferences": {
      "channel_id": 3,
      "escalation_calculation": {
        "first_response_at": "2022-11-15T07:19:04.078Z",
        "last_update_at": "2022-11-15T07:20:05.013Z",
        "last_contact_at": "2022-11-15T07:20:05.013Z",
        "sla_id": 2,
        "sla_updated_at": "2023-01-11T16:02:47.791Z",
        "calendar_id": 2,
        "calendar_updated_at": "2023-01-15T13:20:30.043Z",
        "escalation_disabled": false
      }
    },
    "updated_by_id": 3,
    "created_by_id": 3,
    "created_at": "2022-11-15T07:19:04.022Z",
    "updated_at": "2023-01-16T07:40:29.206Z",
    "last_close_at": null
  }
]

articles:

[
  {
    "id": 130,
    "ticket_id": 53,
    "type_id": 1,
    "sender_id": 1,
    "from": "Stefan Weichinger <[email protected]>",
    "to": "[email protected]",
    "cc": null,
    "subject": "Testanfrage Weichinger",
    "reply_to": null,
    "message_id": "<[email protected]>",
    "message_id_md5": "2bf547f5f570f6a8143ca8084110aee2",
    "in_reply_to": null,
    "content_type": "text/plain",
    "references": null,
    "body": "\nZum Test von Zammad-Emailing.\n\n-- \nViele Grüße | Stefan Weichinger | DW:  | Mobil: \n",
    "internal": false,
    "preferences": {
      "send-auto-response": true,
      "is-auto-response": false
    },
    "updated_by_id": 3,
    "created_by_id": 3,
    "origin_by_id": null,
    "created_at": "2022-11-15T07:19:04.078Z",
    "updated_at": "2022-11-15T07:19:04.078Z",
    "attachments": [],
    "type": "email",
    "sender": "Agent",
    "created_by": "[email protected]",
    "updated_by": "[email protected]"
  },
  {
    "id": 131,
    "ticket_id": 53,
    "type_id": 1,
    "sender_id": 1,
  
[..]

To pipe it into another API I need it in one json-file, like in:

{
    "Ticket": {
        "id": 53,
        "group_id": 2,
        "priority_id": 2,
        "state_id": 2,
        "organization_id": null,
        "number": "740534",
        "title": "Testanfrage Weichinger",
        "owner_id": 3,
        "customer_id": 3,
        "note": null,
        "first_response_at": "2022-11-15T07:19:04.078Z",
        "first_response_escalation_at": null,
        "first_response_in_min": 0,
        "first_response_diff_in_min": 4320,
        "close_at": null,
        "close_escalation_at": null,
        "close_in_min": null,
        "close_diff_in_min": null,
        "update_escalation_at": null,
        "update_in_min": null,
        "update_diff_in_min": null,
        "last_contact_at": "2022-11-15T07:20:05.013Z",
        "last_contact_agent_at": "2022-11-15T07:19:41.008Z",
        "last_contact_customer_at": "2022-11-15T07:20:05.013Z",
        "last_owner_update_at": "2022-11-15T12:08:48.875Z",
        "create_article_type_id": 1,
        "create_article_sender_id": 1,
        "article_count": 33,
        "escalation_at": null,
        "pending_time": null,
        "type": null,
        "time_unit": null,
        "preferences": {
            "channel_id": 3,
            "escalation_calculation": {
                "first_response_at": "2022-11-15T07:19:04.078Z",
                "last_update_at": "2022-11-15T07:20:05.013Z",
                "last_contact_at": "2022-11-15T07:20:05.013Z",
                "sla_id": 2,
                "sla_updated_at": "2023-01-11T16:02:47.791Z",
                "calendar_id": 2,
                "calendar_updated_at": "2023-01-15T13:20:30.043Z",
                "escalation_disabled": false
            }
        },
        "updated_by_id": 3,
        "created_by_id": 3,
        "created_at": "2022-11-15T07:19:04.022Z",
        "updated_at": "2023-01-16T07:40:29.206Z",
        "last_close_at": null,
        "article_ids": [
            130,
            132,
            131,
            243,
            244,
            245,
            415,
            419,
            420,
            411,
            412,
            413,
            414,
            416,
            418,
            421,
            422,
            423,
            417,
            441,
            437,
            438,
            439,
            440,
            442,
            443,
            445,
            447,
            450,
            489,
            492,
            927,
            928
        ],
        "ticket_time_accounting_ids": []
    },
    "articles": [
        {
            "id": 130,
            "ticket_id": 53,
            "type_id": 1,
            
[..]
            "created_by": "[email protected]",
            "updated_by": "[email protected]"
        },
        {
            "id": 131,
            "ticket_id": 53,
            "type_id": 1,
            "sender_id": 1,
            "from": "\"somebody"
            "to": "[email protected]",
            
[..]
}

So I have to add the “label” “articles” to the 2nd array and merge both?

Looked at the Merge-Node, but haven’t managed to get it right so far.
Could somebody point me to an example maybe?

I assume it might also be done in a Code-Node with some lines of script.
Thanks for any pointers!

@sgw I do not see any articles in your articles data, or I’m missing something …

They are there.

Each “id” is an article here:

[
  {
    "id": 130,
    "ticket_id": 53,
    "type_id": 1,
    "sender_id": 1,

[..]

  },
  {
    "id": 131,
    "ticket_id": 53,
    "type_id": 1,
    "sender_id": 1,
  
[..]

Hi @sgw there’s probably a more direct (Code node only) approach to this challenge, but since I was playing around with all the Set and Merge node options, I came up with the following workflow. It’s not meant to be a solution to your challenge, but it may help you to tackle this. And if there’s anybody in the community that has another/more direct solution, please feel free to join this discussion.

@dickhoning wow, thanks. I will look at your workflow asap … might be monday, though.

@dickhoning copied your code to my n8n and looked at it.

Unfortunately the output is not what I look for. And I don’t yet understand what you try to do in the “lower branch” of the workflow. There are 3 articles at the beginning, after splicing there are only 2 items left (why?) and in the end I only see the “Ticket” in the output and no “articles” at all.

Maybe I can progress based on your example, I will see what I come up with. Thanks for your help anyway!

For now I set up a Code-Node to simply return the needed input to the following http-request-node:

return [{json:

  {
    "Ticket": {
        "id": 53,
        "group_id": 2,
        "priority_id": 2,
        "state_id": 2,
        "organization_id": null,
        "number": "740534",
        "title": "Testanfrage Weichinger",
        "owner_id": 3,
        "customer_id": 3,
        "note": null,
        "first_response_at": "2022-11-15T07:19:04.078Z",
        "first_response_escalation_at": null,
        "first_response_in_min": 0,
        "first_response_diff_in_min": 4320,
        "close_at": null,
        "close_escalation_at": null,
        "close_in_min": null,
        "close_diff_in_min": null,
        "update_escalation_at": null,
        "update_in_min": null,
        "update_diff_in_min": null,
        "last_contact_at": "2022-11-15T07:20:05.013Z",
        "last_contact_agent_at": "2022-11-15T07:19:41.008Z",
        "last_contact_customer_at": "2022-11-15T07:20:05.013Z",
        "last_owner_update_at": "2022-11-15T12:08:48.875Z",
        "create_article_type_id": 1,
        "create_article_sender_id": 1,
        "article_count": 2,
        "escalation_at": null,
        "pending_time": null,
        "type": null,
        "time_unit": null,
        "preferences": {
            "channel_id": 3,
            "escalation_calculation": {
                "first_response_at": "2022-11-15T07:19:04.078Z",
                "last_update_at": "2022-11-15T07:20:05.013Z",
                "last_contact_at": "2022-11-15T07:20:05.013Z",
                "sla_id": 2,
                "sla_updated_at": "2023-01-11T16:02:47.791Z",
                "calendar_id": 2,
                "calendar_updated_at": "2023-01-15T13:20:30.043Z",
                "escalation_disabled": false
            }
        },
        "updated_by_id": 3,
        "created_by_id": 3,
        "created_at": "2022-11-15T07:19:04.022Z",
        "updated_at": "2023-01-16T07:40:29.206Z",
        "last_close_at": null,
        "article_ids": [
            130,
            245
        ],
        "ticket_time_accounting_ids": []
    },
    "articles": [
        {
            "id": 130,
            "ticket_id": 53,
            "type_id": 1,
            "sender_id": 1,

[..]

        },
        {
            "id": 245,
            "ticket_id": 53,
            "type_id": 10,
            "sender_id": 1,
            "from": "Stefan Weichinger",
     }
    ]
}
    
 }]

The output looks good in n8n. Is it right to choose “Run Once For All Items” here?

I currently have a few loose ends, so progress stalls: A coder gave me some js-code that “works for him” but not for me :wink: Hard to debug if on his side he pretends that everything works.

I assume some version issues, as his version of node seems to be a year old. And I am not a js-coder myself so that makes it a bit problematic.

Anyway: I’ll try to provide some anonymized and short examples for the topic of this thread asap.

Took the following out of n8n.
These 2 json objects are the outputs of:

  • fetching a ticket from the Zammad-API
  • fetching the articles belonging to that ticket (from the Zammad-API)
# ticket.json
[
  {
    "id": 53,
    "group_id": 2,
    "priority_id": 2,
    "state_id": 2,
    "organization_id": null,
    "number": "740534",
    "title": "Testanfrage Weichinger",
    "owner_id": 3,
    "customer_id": 3,
    "note": null,
    "first_response_at": "2022-11-15T07:19:04.078Z",
    "first_response_escalation_at": null,
    "first_response_in_min": 0,
    "first_response_diff_in_min": 4320,
    "close_at": null,
    "close_escalation_at": null,
    "close_in_min": null,
    "close_diff_in_min": null,
    "update_escalation_at": null,
    "update_in_min": null,
    "update_diff_in_min": null,
    "last_contact_at": "2022-11-15T07:20:05.013Z",
    "last_contact_agent_at": "2022-11-15T07:19:41.008Z",
    "last_contact_customer_at": "2022-11-15T07:20:05.013Z",
    "last_owner_update_at": "2022-11-15T12:08:48.875Z",
    "create_article_type_id": 1,
    "create_article_sender_id": 1,
    "article_count": 3,
    "escalation_at": null,
    "pending_time": null,
    "type": null,
    "time_unit": null,
    "preferences": {
      "channel_id": 3,
      "escalation_calculation": {
        "first_response_at": "2022-11-15T07:19:04.078Z",
        "last_update_at": "2022-11-15T07:20:05.013Z",
        "last_contact_at": "2022-11-15T07:20:05.013Z",
        "sla_id": 2,
        "sla_updated_at": "2023-01-11T16:02:47.791Z",
        "calendar_id": 2,
        "calendar_updated_at": "2023-01-15T13:20:30.043Z",
        "escalation_disabled": false
      }
    },
    "updated_by_id": 3,
    "created_by_id": 3,
    "created_at": "2022-11-15T07:19:04.022Z",
    "updated_at": "2023-01-16T07:40:29.206Z",
     "last_close_at": null
  }
]
# articles.json
[
  {
    "id": 130,
    "ticket_id": 53,
    "type_id": 1,
    "sender_id": 1,
    "from": "Stefan Weichinger <[email protected]>",
    "to": "[email protected]",
    "cc": null,
    "subject": "Testanfrage Weichinger",
    "reply_to": null,
    "message_id": "<[email protected]>",
    "message_id_md5": "2bf547f5f570f6a8143ca8084110aee2",
    "in_reply_to": null,
    "content_type": "text/plain",
    "references": null,
    "body": "\nZum Test von Zammad-Emailing.\n\n-- \nViele Grüße | Stefan Weichinger | DW:  | Mobil: \n",
    "internal": false,
    "preferences": {
      "send-auto-response": true,
      "is-auto-response": false
    },
    "updated_by_id": 3,
    "created_by_id": 3,
    "origin_by_id": null,
    "created_at": "2022-11-15T07:19:04.078Z",
    "updated_at": "2022-11-15T07:19:04.078Z",
    "attachments": [],
    "type": "email",
    "sender": "Agent",
    "created_by": "[email protected]",
    "updated_by": "[email protected]"
  },
  {
    "id": 131,
    "ticket_id": 53,
    "type_id": 1,
    "sender_id": 1,
    "from": "\"Stefan White via company1 Support\" <[email protected]>",
    "to": "[email protected]",
    "cc": "",
    "subject": "Testanfrage Weichinger",
    "reply_to": null,
    "message_id": "<[email protected]mpany1.com>",
    "message_id_md5": "07a9eee59e351c3d068badce3a56c7a0",
    "in_reply_to": "<[email protected]>",
    "content_type": "text/html",
    "references": null,
    "body": "KLappt nun das ANtworten?<br><br><div data-signature=\"true\" data-signature-id=\"1\">  Stefan White<br><br>--<br> Super Support - Waterford Business Park<br> 5201 Blue Lagoon Drive - 8th Floor &amp; 9th Floor - Miami, 33126 USA<br> Email: [email protected] - Web: <a href=\"http://www.example.com/\" rel=\"nofollow noreferrer noopener\" target=\"_blank\">http://www.example.com/</a><br>--</div>",
    "internal": false,
    "preferences": {
      "subtype": "reply",
      "email_address_id": 1,
      "delivery_retry": 1,
      "delivery_channel_id": 3,
      "delivery_status_message": null,
      "delivery_status": "success",
      "delivery_status_date": "2022-11-15T07:19:43.621Z"
    },
    "updated_by_id": 4,
    "created_by_id": 4,
    "origin_by_id": null,
    "created_at": "2022-11-15T07:19:41.008Z",
    "updated_at": "2022-11-15T07:19:43.622Z",
    "attachments": [],
    "type": "email",
    "sender": "Agent",
    "created_by": "[email protected]",
    "updated_by": "[email protected]"
  }
]

The converter I have expects these 2 files combined into one like in:

{
"Ticket": {
    "id": 53,
    "group_id": 2,
    "priority_id": 2,
    "state_id": 2,
    "organization_id": null,
    "number": "740534",
    "title": "Testanfrage Weichinger",
    "owner_id": 3,
    "customer_id": 3,
    "note": null,
    "first_response_at": "2022-11-15T07:19:04.078Z",
    "first_response_escalation_at": null,
    "first_response_in_min": 0,
    "first_response_diff_in_min": 4320,
    "close_at": null,
    "close_escalation_at": null,
    "close_in_min": null,
    "close_diff_in_min": null,
    "update_escalation_at": null,
    "update_in_min": null,
    "update_diff_in_min": null,
    "last_contact_at": "2022-11-15T07:20:05.013Z",
    "last_contact_agent_at": "2022-11-15T07:19:41.008Z",
    "last_contact_customer_at": "2022-11-15T07:20:05.013Z",
    "last_owner_update_at": "2022-11-15T12:08:48.875Z",
    "create_article_type_id": 1,
    "create_article_sender_id": 1,
    "article_count": 3,
    "escalation_at": null,
    "pending_time": null,
    "type": null,
    "time_unit": null,
    "preferences": {
      "channel_id": 3,
      "escalation_calculation": {
        "first_response_at": "2022-11-15T07:19:04.078Z",
        "last_update_at": "2022-11-15T07:20:05.013Z",
        "last_contact_at": "2022-11-15T07:20:05.013Z",
        "sla_id": 2,
        "sla_updated_at": "2023-01-11T16:02:47.791Z",
        "calendar_id": 2,
        "calendar_updated_at": "2023-01-15T13:20:30.043Z",
        "escalation_disabled": false
      }
    },
    "updated_by_id": 3,
    "created_by_id": 3,
    "created_at": "2022-11-15T07:19:04.022Z",
    "updated_at": "2023-01-16T07:40:29.206Z",
    "datev_dokumentennummer": "",
    "last_close_at": null
  },
  "articles": [
  {
    "id": 130,
    "ticket_id": 53,
    "type_id": 1,
    "sender_id": 1,
    "from": "Stefan Weichinger <[email protected]>",
    "to": "[email protected]",
    "cc": null,
    "subject": "Testanfrage Weichinger",
    "reply_to": null,
    "message_id": "<[email protected]>",
    "message_id_md5": "2bf547f5f570f6a8143ca8084110aee2",
    "in_reply_to": null,
    "content_type": "text/plain",
    "references": null,
    "body": "\nZum Test von Zammad-Emailing.\n\n-- \nViele Grüße | Stefan Weichinger | DW:  | Mobil: \n",
    "internal": false,
    "preferences": {
      "send-auto-response": true,
      "is-auto-response": false
    },
    "updated_by_id": 3,
    "created_by_id": 3,
    "origin_by_id": null,
    "created_at": "2022-11-15T07:19:04.078Z",
    "updated_at": "2022-11-15T07:19:04.078Z",
    "attachments": [],
    "type": "email",
    "sender": "Agent",
    "created_by": "[email protected]",
    "updated_by": "[email protected]"
  },
  {
    "id": 131,
    "ticket_id": 53,
    "type_id": 1,
    "sender_id": 1,
    "from": "\"Stefan White via company1 Support\" <[email protected]>",
    "to": "[email protected]",
    "cc": "",
    "subject": "Testanfrage Weichinger",
    "reply_to": null,
    "message_id": "<[email protected]mpany1.com>",
    "message_id_md5": "07a9eee59e351c3d068badce3a56c7a0",
    "in_reply_to": "<[email protected]>",
    "content_type": "text/html",
    "references": null,
    "body": "KLappt nun das ANtworten?<br><br><div data-signature=\"true\" data-signature-id=\"1\">  Stefan White<br><br>--<br> Super Support - Waterford Business Park<br> 5201 Blue Lagoon Drive - 8th Floor &amp; 9th Floor - Miami, 33126 USA<br> Email: [email protected] - Web: <a href=\"http://www.example.com/\" rel=\"nofollow noreferrer noopener\" target=\"_blank\">http://www.example.com/</a><br>--</div>",
    "internal": false,
    "preferences": {
      "subtype": "reply",
      "email_address_id": 1,
      "delivery_retry": 1,
      "delivery_channel_id": 3,
      "delivery_status_message": null,
      "delivery_status": "success",
      "delivery_status_date": "2022-11-15T07:19:43.621Z"
    },
    "updated_by_id": 4,
    "created_by_id": 4,
    "origin_by_id": null,
    "created_at": "2022-11-15T07:19:41.008Z",
    "updated_at": "2022-11-15T07:19:43.622Z",
    "attachments": [],
    "type": "email",
    "sender": "Agent",
    "created_by": "[email protected]",
    "updated_by": "[email protected]"
  }
  ]
}

I assume that could be done in a few lines of js in a Code-Node? Help appreciated! thanks …

Hab mich weiter umgesehen und im Netz einen Tip erhalten, jetzt versuche ich etwas wie:

var tickets = $node["Fetch ticket from Zammad"].json['body'];
var articles = $node["Fetch articles from Zammad"].json['body'];

let combinedTickets = tickets.map(ticket => ({
  Ticket: ticket,
  articles: articles.filter(article => article.ticket_id === ticket.id)
}));

return combinedTickets;

Da bekomme ich aber noch “ERROR: Cannot read properties of undefined (reading ‘map’) [line 4]”.

Stimmt die Richtung, was mache ich falsch? Offensichtlich doch keine “map” …

playing around:

let ticket = $items("Fetch ticket from Zammad")[0].json;
// let articles = $items("Fetch articles from Zammad").json;
let articles2 = $node["Fetch articles from Zammad"].json;

return [{"json": {
  Ticket: ticket,
  articles: articles2,
}}];

Ich bekomme für articles immer nur das erste Item raus, nicht die Liste von allen “articles”. Bitte um einen Hinweis …

bump :thinking: Kann mir da niemand weiter helfen? danke …

let ticket = $("Fetch ticket from Zammad").all;
let articles2 = $("Fetch articles from Zammad").all;

articles_out = articles2.map((article) => {
  return article.json
}) 

return [{"json": {
  Ticket: ticket,
  articles: articles_out,
}}];

gibt mir “ERROR: articles2.map is not a function”

Fast da, denke ich:

let ticket = $items("Fetch ticket from Zammad");
let articles2 = $items("Fetch articles from Zammad");

articles2 = articles2.map((article) => {
  return article.json
} )

return [{"json": {
  Ticket: ticket,
  articles: articles2,
}}];

bin noch am testen … EDIT: ich erhalte 2 Items als Output … warum?

Ein Folgethema: wie pipe ich das dann in den HTTP-Request?

Aber ja, erstmal das mit dem Code-Node fixen, dann weiter. Danke für Hinweise.

Im Test scheint das hier nun zu klappen, bitte gerne korrigieren, wenn erforderlich:

Code-Node, Run once for all items

let ticket = $items("Fetch ticket from Zammad");
let articles_in = $items("Fetch articles from Zammad");

articles_out = articles_in.map((article) => {
  return article.json
} )

return {"json": {
  Ticket: ticket,
  articles: articles_out,
}};

Dieser Node gibt mir aber 2 Items zurück, und nicht nur eines, siehe Screenshot:

Oh, I noticed that I switched from english to german/Deutsch somewhere on the way :wink: sorry for that.

Tested again right now, and still wondering.

Node “Fetch ticket from Zammad” returns one item.
Node “Fetch articles from Zammad” returns one item (for the test-ticket-ID I work with right now).

So I get the ticket:

[
  {
    "id": 907,
    "group_id": 2,
    "priority_id": 2,
    "state_id": 2,
    "organization_id": null,
    "number": "74000009071",
    "title": "Demo-Ticket für Debugging Converter",
    "owner_id": 3,
    "customer_id": 186,
    "note": null,
    "first_response_at": null,
    "first_response_escalation_at": "2023-02-27T09:47:13.000Z",
    "first_response_in_min": null,
    "first_response_diff_in_min": null,
    "close_at": null,
    "close_escalation_at": null,
    "close_in_min": null,
    "close_diff_in_min": null,
    "update_escalation_at": null,
    "update_in_min": null,
    "update_diff_in_min": null,
    "last_contact_at": "2023-02-14T09:47:12.633Z",
    "last_contact_agent_at": null,
    "last_contact_customer_at": "2023-02-14T09:47:12.633Z",
    "last_owner_update_at": null,
    "create_article_type_id": 5,
    "create_article_sender_id": 2,
    "article_count": 1,
    "escalation_at": "2023-02-27T09:47:13.000Z",
    "pending_time": null,
    "type": null,
    "time_unit": null,
    "preferences": {
      "escalation_calculation": {
        "last_update_at": "2023-02-14T09:47:12.633Z",
        "last_contact_at": "2023-02-14T09:47:12.633Z",
        "sla_id": 2,
        "sla_updated_at": "2023-01-11T16:02:47.791Z",
        "calendar_id": 2,
        "calendar_updated_at": "2023-02-13T13:23:29.017Z",
        "escalation_disabled": false
      }
    },
    "updated_by_id": 3,
    "created_by_id": 3,
    "created_at": "2023-02-14T09:47:12.536Z",
    "updated_at": "2023-02-14T09:47:13.017Z",
    "datev_dokumentennummer": "",
    "last_close_at": null
  }
]

and the article(s):

[
  {
    "id": 1398,
    "ticket_id": 907,
    "type_id": 5,
    "sender_id": 2,
    "from": "Stefan G. Weichinger <[email protected]>",
    "to": "Administration",
    "cc": null,
    "subject": null,
    "reply_to": null,
    "message_id": null,
    "message_id_md5": null,
    "in_reply_to": null,
    "content_type": "text/html",
    "references": null,
    "body": "Demo Text eins",
    "internal": false,
    "preferences": {},
    "updated_by_id": 3,
    "created_by_id": 3,
    "origin_by_id": 186,
    "created_at": "2023-02-14T09:47:12.633Z",
    "updated_at": "2023-02-14T09:47:12.633Z",
    "attachments": [],
    "type": "phone",
    "sender": "Customer",
    "created_by": "[email protected]",
    "updated_by": "[email protected]",
    "origin_by": "[email protected]"
  }
]

The Code-Node looks like this right now (Mode “Run Once for All Items”):

let ticket = $items("Fetch ticket from Zammad");
let articles_in = $items("Fetch articles from Zammad");

// press F12 for browser console
// console.log(ticket);
// console.log(articles);

articles_out = articles_in.map((article) => {
  return article.json
} )

console.log(articles_out);

return {"json": {
  Ticket: ticket,
  articles: articles_out,
}};

When I run the workflow in the editor I get 2 items returned by the Code node.

Then I doubleclick the Code node, click “Execute node” and get only 1 item returned.

Do I use it wrong or is there a bug? For sure, my code above is cut and paste and trial and error. As mentioned I am no js-coder at all …

bump help appreciated!

I assume that function building “articles_out” is wrong, could someone give me a hint, please?

Hi @sgw, from looking at this screenshot it seems you’re not actually merging the data. Instead, each branch coming in on your Code node would trigger a new execution of your Code node.

If you want to merge your items via the Code node rather than the designated Merge node you’d need to ensure you run your nodes in sequential order and only have one branch coming into the Code node.

For example:

This example uses a public mock API, so you can easily run it yourself without any additional setup.

You’ll notice how I am using the Execute Once option to prevent the HTTP Request nodes from making additional requests for each incoming item:

The code itself uses the $('HTTP Request 1: Fetch posts').all(); method to fetch all items from previous nodes. This method (and other relevant methods and variables) are documented here.

Hope this helps!

@MutedJam yes, you are right, the subject of the issue wasn’t chosen correctly. And I didn’t find out if and how to change it.

I already received help from someone else aside from this forum, and his solution also switched to sequential processing. I will try your suggested snippet now and play with it. Learning all the time!

thanks so far, I will report back later.

1 Like