How to pass a date time as a repeated JSON to Set node

Describe the problem/error/question

I have a splitinbatches node that outputs 10 sheet rows at a time. i also have a javascript function node that gives me date and time in IST. I have a set function that takes these two as input. but the date value appears only once, since there is no loop inside the function. so, out of 10 rows, only one row gets a date time stamp.
how to ensure that all these 10 items get the same value from the function.

What is the error message (if any)?

Please share your workflow

image

Javascript function:
var date = new Date().toLocaleString(‘en-US’, {timeZone: ‘Asia/Kolkata’})

var day = new Date().getDay();

//const weekday = [“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”];

var inputLength = 2;

for (i=0;i<inputLength;i++){

items[i].json.date_today = date;

//items[0].json.day_today = weekday[day];

}

return items;

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @kalai, when branching out your execution as shown in your screenshot you’ll essentially duplicate the items. One copy of the items from your SplitInBatches node is sent to your Function node, another copy to your Set node. Based on your description it doesn’t sound like that’s what you want.

I imagine the easiest thing to do here would be to use either the Function Item node or the Code node running for reach item (depending on the version of n8n you have in use) instead of the Function node. This way you wouldn’t have to branch out anything and can simply add your new field to every single item.

1 Like

Tried and this option worked, thank you :slight_smile:

1 Like

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