
Announcements
In my model-driven app, I'm opening a form from javascript using Xrm.Navigation.openForm with parameters to auto populate some fields. One of the fields is of type Date Only, with behavior set to "Date Only". I'm assigning the parameter value with a string formatted as "yyyy-MM-dd". When the form opens, the value is off by one day. For example, if it assign the parameter the value "2021-09-02", the form opens with the field value of "9/1/2021".
This seems like a bug to me. Anyone know of a fix other than adding code in the OnFormLoad event to add 1 day to each Date Only value?
Hi @tschopp ,
I suppose that the problem is about the user time. When you use in javascript, the Date() it will be automatically converted to user time.
When I make a new Date for 2nd Aug 2021, I get 2021-09-01T22:00:00Z (in my case Central European Sommer Time)
The "DateOnly" wil be considered on the server side, when saving, but I guess this date is parsed in javascript.
One way would be to pass the date including the hour:
new Date(2021, 8, 2).toISOString()
If this doesn't work, as a cheap workaround, I suggest passing the date for 12 a clock. That should be the same day for all time zones.
new Date(2021, 8, 2, 12).toISOString()
Hope this helps!