In Dynamics 2015 Update 1, a small update was released that you might have missed called Change Tracking. This feature is implemented via the CRM SDK and let’s developers query for changes to the system, supplying a watermark (the token) from the last fetch to start retrieving from in the next fetch.
In terms of data retrieval, this is a big feature as no longer do you need to add fields into Dynamics to store this information and instead can leverage the platform as is to return this data and keep track of it for you.
For this post, I used the code from MSDN, modifying it slightly.
Enabling Change Tracking
Change Tracking is enabled on a per-entity basis – another great idea as it enforces the notion of “only use what you need”. To enable this setting for an entity, create a new solution, go to the entity’s information page and click the box called “Change Tracking”, from there save and publish your solution.
If you were not to enable your entity for Change Tracking and then tried to run the code to access it’s Change Tracking History you would get the very direct message below.
First Time Execution
The first time you run the sample code, you will see all the records that match your query are returned but this time with a token attached to them.
Setting the Token
When you execute the code you are returned a token for each request/response. If you persist this token as seen below on return from the server, the next time you request information you can pass that token into the DataVersion parameter which will tell Dynamics to only return the records that have changed since then.
As you can now see in this example, after persisting my token, when I go to run the code again (and after having added 1 record to my entity in Dynamics), I now only see one result being returned and a new token being returned.
For those of you working with data and having to migrate/synchronize data on an ongoing basis this is great addition to the SDK that should save you lots of needless time in constant iterating and validation.
In addition, once you receive the results, you can delve further into the records themselves, identifying the changes and their types. More information on this is available at Kingsway Software’s Blog.