Unable to get JSON value in Function_Item node

I have data in this format. Now, I am trying to extract only the “dateTime” value in each item.

[
  {
    "start": {
      "dateTime": "2019-12-09T16:00:00+05:30",
      "timeZone": "Asia/Kolkata"
    },
....
....
},
{
    "start": {
      "dateTime": "2019-12-09T16:00:00+05:30",
      "timeZone": "Asia/Kolkata"
    },
....
....
}
]

I tried to use functionItem node for this. But when I try to get the dateTime value, I get an error. Here is the code I use.

myVariable = item.start;
return [{
    json: {myVariable: myVariable.dateTime}
    }]

A similar format works when I try to use Function node. But doesn’t work with functionitem. Appreciate any help here.

Error response

ERROR: Cannot read property 'dateTime' of undefined
TypeError: Cannot read property 'dateTime' of undefined
at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:3:35
at Object.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:5:2)
at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/main.js:1121:29)
at Object.executeSingle (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/FunctionItem.node.js:72:33)
at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:474:60)
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:395:62
at processTicksAndRejections (internal/process/task_queues.js:93:5)

Hi @ItisallBlue,

To extract dateTime property you need to

  1. Add a Function node

  2. Add next code

     return items.map(function(item) {
       return {
         json: {
            dateTime: item.json.start.dateTime
         }
       };
     }) ;
    

Hope this helps.

Got the same error.

Can you share code in previous node please?

I think we are working with different JSON output.
My first node returns this JSON (in a Function node)

[
{
"start": {
"dateTime": "2019-12-09T16:00:00+05:30",
"timeZone": "Asia/Kolkata"
}
},
{
"start": {
"dateTime": "2019-12-09T16:00:00+05:30",
"timeZone": "Asia/Kolkata"
}
}
]

After applying commented code in the next Function node

return items.map(function(item) {
   return {
     json: {
        dateTime: item.json.start.dateTime
     }
   };
 }) ;

I get

[
{
"dateTime": "2019-12-09T16:00:00+05:30"
},
{
"dateTime": "2019-12-09T16:00:00+05:30"
}
]

Could you share the returned JSON code in your first node (what you see in the JSON tab of your first node after executing workflow)?

Thank you!

[
  {
    "kind": "calendar#event",
    "etag": "\"31920\"",
    "id": "41cc04",
    "status": "confirmed",
    "htmlLink": "m/calendar/event?eid=NDFj",
    "created": "2019-12-06T02:08:59.000Z",
    "updated": "2020-08-03T08:23:13.528Z",
    "summary": "Design Weekly Review ",
    "description": "",
    "creator": {
      "email": "",
      "self": true
    },
    "organizer": {
      "email": "",
      "self": true
    },
    "start": {
      "dateTime": "2019-12-09T16:00:00+05:30",
      "timeZone": "Asia/Kolkata"
    },
    "end": {
      "dateTime": "2019-12-09T16:50:00+05:30",
      "timeZone": "Asia/Kolkata"
    },
    "recurrence": [
      "RRULE:FREQ=WEEKLY;UNTIL=20200119T182959Z;BYDAY=MO"
    ],
    "iCalUID": "leom",
    "sequence": 0,
    "attendees": [
      {
        "email": "",
        "responseStatus": "needsAction"
      },
      {
        "email": "",
        "responseStatus": "accepted"
      },
      {
        "email": "",
        "responseStatus": "needsAction"
      },
      {
        "email": "",
        "responseStatus": "accepted"
      }
    ],
    "hangoutLink": ".com/und-cqnt",
    "conferenceData": {
      "entryPoints": [
        {
          "entryPointType": "video",
          "uri": "com/un",
          "label": "und"
        },
        {
          "entryPointType": "more",
          "uri": "jad?pin=645,
          "pin": "645"
        },
        {
          "regionCode": "US",
          "entryPointType": "phone",
          "uri": "tel:+1-401-379-",
          "label": "+1 401-379-“,
          "pin": "783"
        }
      ],
      "conferenceSolution": {
        "key": {
          "type": "hangoutsMeet"
        },
        "name": "Google Meet",
        "iconUri": ""
      },
      "conferenceId": "und",
      "signature": "AL9ov"
    },
    "guestsCanModify": true,
    "reminders": {
      "useDefault": true
    },
    "eventType": "default"
  },
  {
    "kind": "calendar#event",
    "etag": "\"32002828\"",
    "id": "5l3rgu50kh",
    "status": "confirmed",
    "htmlLink": "ar/event?eid=NWwzcmd1vMGhsZ2dicXZsbmpfMjAxO",
    "created": "2019-12-02T12:14:01.000Z",
    "updated": "2020-09-15T03:44:04.822Z",
    "summary": "Weekly Sync-up",
    "description": "",
    "creator": {
      "email": ""
    },
    "organizer": {
      "email": ""
    },
    "start": {
      "dateTime": "2019-12-09T12:00:00+05:30",
      "timeZone": "Asia/Kolkata"
    },
    "end": {
      "dateTime": "2019-12-09T13:00:00+05:30",
      "timeZone": "Asia/Kolkata"
    },
    "recurrence": [
      "RRULE:FREQ=WEEKLY;UNTIL=20200119T182959Z;BYDAY=MO"
    ],
    "iCalUID": "5l3rgu50khglcom",
    "sequence": 0,
    "attendees": [
      {
        "email": "",
        "self": true,
        "responseStatus": "needsAction"
      },
      {
        "email": "",
        "responseStatus": "needsAction"
      },
      {
        "email": "",
        "responseStatus": "needsAction"
      }
    ],
    "hangoutLink": "gm/npi-",
    "conferenceData": {
      "entryPoints": [
        {
          "entryPointType": "video",
          "uri": "/npi-",
          "label": "lm/npi"
        },
        {
          "entryPointType": "more",
          "uri": "t/npi?pin=63",
          "pin": "63"
        },
        {
          "regionCode": "US",
          "entryPointType": "phone",
          "uri": "tel:+1-650-466-",
          "label": "+1 650-466-",
          "pin": "81"
        }
      ],
      "conferenceSolution": {
        "key": {
          "type": "hangoutsMeet"
        },
        "name": "Google Meet",
        "iconUri": ""
      },
      "conferenceId": "npi",
      "signature": "AL"
    },
    "reminders": {
      "useDefault": true
    },
    "eventType": "default"
  }
]

I have replaced your code in a function node this way

return [{
    "json": {
      "kind": "calendar#event",
      "etag": "31920",
      "id": "41cc04",
      "status": "confirmed",
      "htmlLink": "m/calendar/event?eid=NDFj",
      "created": "2019-12-06T02:08:59.000Z",
      "updated": "2020-08-03T08:23:13.528Z",
      "summary": "Design Weekly Review ",
      "description": "",
      "creator": {
        "email": "",
        "self": true
      },
      "organizer": {
        "email": "",
        "self": true
      },
      "start": {
        "dateTime": "2019-12-09T16:00:00+05:30",
        "timeZone": "Asia/Kolkata"
      },
      "end": {
        "dateTime": "2019-12-09T16:50:00+05:30",
        "timeZone": "Asia/Kolkata"
      },
      "recurrence": [
        "RRULE:FREQ=WEEKLY;UNTIL=20200119T182959Z;BYDAY=MO"
      ],
      "iCalUID": "leom",
      "sequence": 0,
      "attendees": [{
          "email": "",
          "responseStatus": "needsAction"
        },
        {
          "email": "",
          "responseStatus": "accepted"
        },
        {
          "email": "",
          "responseStatus": "needsAction"
        },
        {
          "email": "",
          "responseStatus": "accepted"
        }
      ],
      "hangoutLink": ".com/und-cqnt",
      "conferenceData": {
        "entryPoints": [{
            "entryPointType": "video",
            "uri": "com/un",
            "label": "und"
          },
          {
            "entryPointType": "more",
            "uri": "jad?pin=645",
            "pin": "645"
          },
          {
            "regionCode": "US",
            "entryPointType": "phone",
            "uri": "tel:+1-401-379-",
            "label": "+1 401-379-",
            "pin": "783"
          }
        ],
        "conferenceSolution": {
          "key": {
            "type": "hangoutsMeet"
          },
          "name": "Google Meet",
          "iconUri": ""
        },
        "conferenceId": "und",
        "signature": "AL9ov"
      },
      "guestsCanModify": true,
      "reminders": {
        "useDefault": true
      },
      "eventType": "default"
    }
  },
  {
    "json": {
      "kind": "calendar#event",
      "etag": "32002828",
      "id": "5l3rgu50kh",
      "status": "confirmed",
      "htmlLink": "ar/event?eid=NWwzcmd1vMGhsZ2dicXZsbmpfMjAxO",
      "created": "2019-12-02T12:14:01.000Z",
      "updated": "2020-09-15T03:44:04.822Z",
      "summary": "Weekly Sync-up",
      "description": "",
      "creator": {
        "email": ""
      },
      "organizer": {
        "email": ""
      },
      "start": {
        "dateTime": "2019-12-09T12:00:00+05:30",
        "timeZone": "Asia/Kolkata"
      },
      "end": {
        "dateTime": "2019-12-09T13:00:00+05:30",
        "timeZone": "Asia/Kolkata"
      },
      "recurrence": [
        "RRULE:FREQ=WEEKLY;UNTIL=20200119T182959Z;BYDAY=MO"
      ],
      "iCalUID": "5l3rgu50khglcom",
      "sequence": 0,
      "attendees": [{
          "email": "",
          "self": true,
          "responseStatus": "needsAction"
        },
        {
          "email": "",
          "responseStatus": "needsAction"
        },
        {
          "email": "",
          "responseStatus": "needsAction"
        }
      ],
      "hangoutLink": "gm/npi-",
      "conferenceData": {
        "entryPoints": [{
            "entryPointType": "video",
            "uri": "/npi-",
            "label": "lm/npi"
          },
          {
            "entryPointType": "more",
            "uri": "t/npi?pin=63",
            "pin": "63"
          },
          {
            "regionCode": "US",
            "entryPointType": "phone",
            "uri": "tel:+1-650-466-",
            "label": "+1 650-466-",
            "pin": "81"
          }
        ],
        "conferenceSolution": {
          "key": {
            "type": "hangoutsMeet"
          },
          "name": "Google Meet",
          "iconUri": ""
        },
        "conferenceId": "npi",
        "signature": "AL"
      },
      "reminders": {
        "useDefault": true
      },
      "eventType": "default"
    }
  }
]

and response is this output

[
{
"dateTime": "2019-12-09T16:00:00+05:30"
},
{
"dateTime": "2019-12-09T12:00:00+05:30"
}
]

So this is the expected behaviour.

Something is different between your workflow and mine but no idea what.

Could you share your full workflow please (you can attach downloaded file here)?
Perhaps somebody else could help you.

Thanks,

1 Like

https://drive.google.com/file/d/14vvImgz5oGZlyM5UWqm_Ip3Qt-rOu69m/view?usp=sharing

There is no issue with the content. Your nodes work for me. It probably must be due to the format n8n returns the data.

Can anyone help here please?

Sorry I do sadly not understand what the issue is.

The Function-Node from your workflow above seems to work fine:

 return items.map(function(item) {
   return {
     json: {
        dateTime: item.json.start.dateTime
     }
   };
 }) ;

What you want is to simply have the same code in a Function Item-Node instead?

Or what do you mean with: “There is no issue with the content. Your nodes work for me. It probably must be due to the format n8n returns the data.”

The same nodes seem to work now :face_with_hand_over_mouth:

I’ll reopen this if it happens again.

Ah glad to hear. Have fun!