Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / same createdDateTime w...
Finance forum
Suggested answer

same createdDateTime when creating records

Posted on by 170
Hi,

How can I make sure that I insert two records in the same table, and these two records have exactly the same createdDateTime? even if i do it in the same transaction would that gurantee that those two records will always have the same exact createdDateTime?
  • Martin Dráb Profile Picture
    Martin Dráb 224,528 Super User on at
    same createdDateTime when creating records
    Could you react to my first question, please? As far as I know, change tracking isn't based on CreatedDateTime, therefore you seem to be solving a wrong problem.
     
    The change tracking table will be updated when the transaction is committed. If you create both orders in the same transaction, they (and their change tracking entries) will became visible to the rest of the system at the same time (when the transaction gets committed).
     
    Do you have some tests that prove me wrong?
     
    CreatedDateTime isn't available in all tables and it doesn't have any information about updates, which change tracking takes into account.
     
    Regarding your example, you're saying that you created SO2 and SO3 at almost the same time, but then you're saying that you want to export different orders together: SO3 and SO4. To me, it sounds like a very different scenario than what we discussed so far. You talked about orders created in the same transaction at the same time, while SO3 and SO4 were created twenty seconds apart. The fact that you created SO4 before SO3 and SO2 sounds suspicious too.
     
    Which orders did you create in the same transaction?
     
     
  • CU04051814-0 Profile Picture
    CU04051814-0 170 on at
    same createdDateTime when creating records
    Hi Martin,

    I didn't say that createdDateTime is used to link the orders -- my issue with createdDateTime is another thing. I will try to explain again

    So let's say we have the following orders

    SalesId   isLinked     LinkedId  createdDateTime
    SO1             0             ""               11:57:00 AM
    SO2             0             ""               12:00:19 AM
    SO3             1             SO4           12:00:21 AM   
    SO4             0             ""               12:00:01 AM 
    SO5             0             ""               05:00:00 PM

    So as you can see SO2 and SO3 got created approximately at the same time, as by code when there is a link those two gets created together.

    Now my issue is with recurring integration (recurrence one minute)
    As i said before whenever an update/insert occurs, those orders need to be sent to another system. And if there is a link, we need to make sure that those linked orders go to the other system in the same file.

    So let's say in a rare case, recurring integration started at 11:56:20
    11:56:20  no records will get exported
    11:75:20  SO1 will be exported
    11:58:20  no records will get exported
    11:59:20  no records will get exported
    12:00:20  SO3 will be exported
    12:01:20  SO4 will be exported

    So my issue here is that SO3 and SO4 weren't in the same export -- same issue might occur in case of update
  • Martin Dráb Profile Picture
    Martin Dráb 224,528 Super User on at
    same createdDateTime when creating records
    As far I know, change tracking utilizes SQL Server Change Tracking, not CreatedDateTime field. Am I mistaken?
     
    IsLinked and CreatedDateTime doesn't sounds like a reasonable link of the related orders to me. You should use a SalesId reference, or a separate link table (especially if there may be more than two related orders).
     
    If you use a field for the SalesId reference, you also don't need to create any "dummy" field.
  • CU04051814-0 Profile Picture
    CU04051814-0 170 on at
    same createdDateTime when creating records
    Hi Anthony,

    New field won't work in my case, i explained in the previous reply what is my exact issue.

    The Scenario in short is that, when any order gets created or updated, they need to be sent to another system via middleware (Recurring integration is used)

    A special case, is that when linked orders get created/updated, they need to be sent in the same file to the other system. So the issue is that maybe in rare cases, if there is a 1 second difference or more, then this will cause those linked orders to be in a separate file. Maybe if u re-read now my previous reply now it will make more sense
  • Anthony Blake Profile Picture
    Anthony Blake 932 on at
    same createdDateTime when creating records
    As you've found, the Created Date Time isn't a field you can guarantee will be the same across records, so why not just add a custom field. You can treat it however you would like
  • CU04051814-0 Profile Picture
    CU04051814-0 170 on at
    same createdDateTime when creating records
    Hi Martin,

    I need to enable change tracking and use recurring integration, and as you know change tracking only works with single entities. If I want change tracking for composite entity, then customization is need where I can create a log table (so I don't want the composite option)

    Currently my entity has order lines inner joined with headers lines. Let's think of it as SalesLine inner Join SalesTable (real scenario is not sales order)

    now there are some cases where two separate orders are linked together from a business point of view via a field. Let's say isLinked=1

    if there is a link, these two orders get created at the same and most of the time i can see createdDateTime is the same, but sometimes there is a 1 second difference.

    Issues:
    1. Now my recurring integration is setup every 1 minute. So let's say the next recurring integration will start at 12:00:00
    and what if the first order got created at 11:00:59 (which means it will be sent to the middle ware at 12:00:00) But what if the 2nd order got created at 12:00:01, this will mean that those two orders will be sent in separate jobs but the middle ware needs to see them together in order to send them to the other system together... What can I do in this case?

    2. Also, in case one of  the linked ones got updated, I updated a dummy field in the other order, to make sure "change tracking" catches both together, but also this 1 second issue might also happen, what can be done?

    Any ideas?
  • Martin Dráb Profile Picture
    Martin Dráb 224,528 Super User on at
    same createdDateTime when creating records
    Please explain what business problem you're trying to address, so we can suggest a better solution. The solution you chose is impossible to implement. If records are inserted a second apart, the fact that you see one second difference in CreatedDateTime is the correct behavior and you can't change that.
  • CU04051814-0 Profile Picture
    CU04051814-0 170 on at
    same createdDateTime when creating records
    Hi Anthony,

    I mean that I need to make sure that these two records have the same createdDateTime when i create them by code. How can i gurantee this? is the same transction enough to gurantee this? i don't want them to be created with a 1 second difference, they need to be the same
  • Suggested answer
    Anthony Blake Profile Picture
    Anthony Blake 932 on at
    same createdDateTime when creating records
    I would use an additional field so that you have control over the contents. CreatedDate/Time can then continue to work as it is supposed to.

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,632 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,528 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans