AX 2012 R3 CU10:
I've created a new table and added an UtcDateTime type field.
I'm using this table to import orders from a web service. So my code is:
MyTable MyTable; str mydatetime; ; for (i = 1; i <= result.lastindex(); i++) { data = result.value(i); MyTable.id = data.lookup('id'); if (!MyTable::find(MyTable.id)) { ttsBegin; mydatetime = data.lookup('creado'); if (mydatetime == '0000-00-00 00:00:00') { mydatetime = '2017-01-11 00:00:00'; } //MyTable.OrderDateTime = str2datetime(mydatetime,321); Commented because it inserts an empty date MyTable.insert(); MyTable.OrderDateTime = str2datetime(mydatetime,321); MyTable.update(); ttsCommit; } }
I have two issues:
First, I don't understand why I need to insert and then update. When directly inserting, the OrderDateTime field is empty
Second, if mydatetime is for example 2017-07-12 12:18:05, it inserts 2017-07-12 13:18:05 (it adds an extra hour)
*This post is locked for comments
If you successfully set the value of OrderDateTime (please verify it in debugger) and it disappeared in insert(), it probably means that you have code in insert() that removes it. If you there is no value even before insert, debug and fix the broken code that should set it. For example, if mydatetime contains an invalid value, the conversion to date will fail.
Second issue could be related to GMT/ time zone.
OK.. for the second issue, I found that system applies the default timezone to the saved value.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156