[4.2] - Creating new date javascript doesn't work - server-side - Forum - Rollbase - Progress Community

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

 Forum

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

This question is not answered

Hello,

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?

Code:

var dateVal = new Date("2016-11-04T15:50:54.0664381+00:00"); // results in Invalid Date
All Replies
  • 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.

    TestMomentsJS_v1.xml

    Regards,
    Siraj.
  • 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?
     
    Cheers,
    Iram
     
  • 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.