Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Inserting on a custom UtcDateTime field.

Posted on by 2,983

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

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Inserting on a custom UtcDateTime field.

    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.

  • Suggested answer
    Ajit Profile Picture
    Ajit 8,755 on at
    RE: Inserting on a custom UtcDateTime field.

    Second issue could be related to GMT/ time zone.

  • Ghetz Profile Picture
    Ghetz 2,983 on at
    RE: Inserting on a custom UtcDateTime field.

    OK.. for the second issue, I found that system applies the default timezone to the saved value.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans