[4.2] - Creating new date javascript doesn't work - serv

Posted by IramK on 04-Nov-2016 12:42


I was trying to create a trigger/batch job that would take on a date in UTC format and assign it to a javascript date object. However, every time I try to do this, it gives me an invalid date. Is this something to do with the server-side javascript engine?

This converts to a valid javascript date object on client-side but not server-side. Any reasons why?


var dateVal = new Date("2016-11-04T15:50:54.0664381+00:00"); // results in Invalid Date

All Replies

Posted by Mohammed Siraj on 04-Nov-2016 12:54

Hello Iram,

Parsing Date string literals into Date objects can be an issue with specific date formats.

Can you please consider passing a long argument i.e. time in milliseconds instead to Date construction or Date.valueOf.

Else, you can leverage Moments.js JavaScript library for server-side scripts. Attached is a sample application exhibiting the same.


Posted by IramK on 09-Nov-2016 04:10
Hello Siraj,
I managed to do it a bit differently.
var startDate = new Date(dateStringInUTCFormat.replace("T", " ").replace(/-/g, "/")); // returns a valid javascript date
Not sure if this is the best way though. Would there be support for all date formats in the future?
Posted by mpiscoso@gmail.com on 15-Nov-2016 19:21

Have you tried using rbv_api.getFieldValue() instead of your date's token?

It might give you a properly formatted date.

Also, you might want to look into rbv_api.formatDate(date, pattern) for future reference

Hope this helps.

This thread is closed