postUpdate for DateTime items from ECMAScript script

Hey there!

I am currently trying to fetch some dates from a web-scraping service I developed for our garbage collection.

I got multiple DateTime items that I would like to update with postUpdate.
However it does not work because I always get an error:

java.lang.IllegalArgumentException: The argument 'state' must not be null.

My script:

// Get Json from the service
var result = JSON.parse(httpGet("http://192.168.178.20:8080/garbage?streetId=60C28030&number=291").body());

// Get dates from the array for the different types of garbage
var yellowDate = result.filter(function(el) { return el.type== "yellow" })[0].dates[0];
var blueDate = result.filter(function(el) { return el.type== "blue" })[0].dates[0];
var greyDate = result.filter(function(el) { return el.type== "grey" })[0].dates[0];

// Update items with the dates
events.postUpdate("GarbageCollectionDate_Yellow", new Date(Date.parse(yellowDate)));
events.postUpdate("GarbageCollectionDate_Blue", new Date(Date.parse(blueDate)));
events.postUpdate("GarbageCollectionDate_Grey", new Date(Date.parse(greyDate)));

I think the syntax is events.postUpdate( string, string )

1 Like

So what would be your suggestion? I tried calling toString on the date objects, but it stilly says “The argument ‘state’ must not be null.”

Why not add some logging? Maybe whatever you’re extracting will not parse as a date. Do javascript date objects have a .toString method, I thought you needed to be specific like .toISOString?

1 Like

I actually just tried using toISOString and it worked! <3