Question

JQL Error: Uncaught exception RangeError: Invalid time value

  • 10 October 2019
  • 1 reply
  • 234 views

Badge

Hello all,

I am presently writing a JQL query to join a group of Events with People, and then group by an array of keys. One of those keys happens to be time, as you can see below:

function main() {
var collection = join(
Events({
from_date: '2019-09-01',
to_date:   '2019-09-03',
event_selectors: [{event: 'Page Viewed'}]
}),
People({
user_selectors: []
}),
{type:'left'})

return collection.groupBy(mixpanel.multiple_keys(['properties.User Id', 'properties.Organisation Id', function(event) {return (new Date(event.time)).toISOString().split('T')[0];}]),
mixpanel.reducer.count())
}

Which gives me the following error:

Stack trace: RangeError: Invalid time value    at Date.toISOString (<anonymous>)    at <anonymous>:13:150

I've noticed that:

1) The error persists even when I toggle to other join types.

2) The error disappears if I remove the join operation with People and just leave events. But I would like to keep the join operation so that I can only count events linked to People profiles.

Anyone know a fix? I'm guessing its as simple as a quick type conversion function on the time property. Thanks.



1 reply

Badge +1

Hi @michael.ma@century.tech,


Looks like the issue is you're trying to access the 'time' key in the event, but the items in your collection are not events, they're tuples with both event and people data included in them.


The format of an item in your collection after an events/people join looks something like this:


{
distinct_id: 'xyz',
event: {
distinct_id: 'xyz'
name: 'event name'
time: 'event time',
properties: { your properties }
}
user: {
distinct_id: 'xyz'
last_seen: 'last seen',
properties: { your properties }
}
}


The functions in the groupBy() get run on one item in your collection at a time. So rather than calling your parameter 'event', it's more accurate to call it something like 'item'.

If you use this function, it should work:

function(item) {return (new Date(item.event.time)).toISOString().slice(0,10);}


^the above is guaranteed to work on the join you made because it's a left join (which means all items are guaranteed to have event data). If you instead did a right join or full join, you'd get errors in situations where you have people data for a user but no event data in the date range.


Hope that helps!


Thanks,

Evan


Reply