Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Web API - Change tracking a subset of data

(0) ShareShare
ReportReport
Posted on by 10

The `Prefer: odata.track-changes` header is pretty useful to synchronize entire entities.

However this seems to work only if the user has a Global level prvRead<Entity> priviledge.

Otherwise it's returning this kind of error:

GET /api/data/v9.2/accounts?$select=name
Prefer: odata.track-changes

SecLib::CheckPrivilege failed. User: xxxxxxxxxxxxxxxxxxxxxxxxxxx, PrivilegeName: prvReadAccount, PrivilegeId: xxxxxxxxxxxxxxxxxxxxxxxxxxx, Required Depth: Global, BusinessUnitId: xxxxxxxxxxxxxxxxxxxxxxxxxxx, MetadataCache Privileges Count: 7356, User Privileges Count: 586

I'm guessing this is also why query options are not allowed in a "track-changes" request.

In another hand this seems to be based on the native SQLServer Change Tracking feature, which seems to me that could allow filtering.
Couldn't we "simply" join the result of CHANGETABLE() internally ?

So my final question is: How can I track the changes of data accessible by a user for a specific entity for which he does not have the global level privilege ?

Maybe I should not use track-changes

  • Glide Profile Picture
    Glide 10 on at
    RE: Web API - Change tracking a subset of data

    I'll try to do my own synchro system so.

    Thanks again

  • Guido Preite Profile Picture
    Guido Preite 54,087 Super User 2024 Season 1 on at
    RE: Web API - Change tracking a subset of data

    For my experience I usually stay far away from the offline mobile feature. I don't know if it's possible to use the engine for a custom integration (maybe not all the API are available) but also in that case I would not use it.

  • Glide Profile Picture
    Glide 10 on at
    RE: Web API - Change tracking a subset of data

    Another idea would be to rely on the mobile offline feature but it seems reserved for PowerApps & FieldService, isn't it ?

    Can we use that through FetchXml ?

  • Glide Profile Picture
    Glide 10 on at
    RE: Web API - Change tracking a subset of data

    Indeed inactive "soft delete" is an idea too, I'll think about it.

    However I'd just like to make sure I can't do this SQL equivalent (inspired from CHANGETABLE doc) through FetchXml:

    SELECT
      c.accountid
    , a.name
    , c.SYS_CHANGE_VERSION, c.SYS_CHANGE_OPERATION,
    , c.SYS_CHANGE_COLUMNS, c.SYS_CHANGE_CONTEXT
    FROM CHANGETABLE (CHANGES Accounts, @last_sync_version) AS c
    JOIN DynamicsSecurity AS d (c.accountid = d.accountid)
    LEFT JOIN Accounts AS a ON (a.accountid = c.accountid)
    WHERE d.user = @user
    ;

    I'm abstracting the DynamicsSecurity here because I don't know how it's implemented, but it gives the idea.

    @user & @last_sync_version are contextual.

  • Guido Preite Profile Picture
    Guido Preite 54,087 Super User 2024 Season 1 on at
    RE: Web API - Change tracking a subset of data

    In Dynamics you don't have the concept of soft-delete (so when a record is deleted is removed completely) but they have the active and inactive status (statecode field). You may "delete" the records putting them as Inactive.

    However these are logic on the synchronization, you can decide how it operates as the change tracking data is not suitable for your needs

  • Glide Profile Picture
    Glide 10 on at
    RE: Web API - Change tracking a subset of data

    Thank you for your quick answer.

    Here I'm talking about keeping track of changes for a certain amount of data.

    I though about etag but there is one by object so I can hardly track changes on a big volume (without comparing each object's etag one by one), can I ?

    `modifiedon` would be interesting but how to get the deleted objects since the latest sync ?

    The change tracking feature seemed really close to what I was searching for, but it seems very limited and technically it would not need much to be able to get rid of this limitation.

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,087 Super User 2024 Season 1 on at
    RE: Web API - Change tracking a subset of data

    I was not aware of that limitation but the error is pretty clear stating Global depth is required.

    Regarding the SQL Server feature, keep in mind that Dataverse is still a layer built on top of SQL Server, this means that functions need to be implemented and more important Dataverse is now not only used with a SQL Server backend but also to other data sources (I am referring to Virtual Tables).

    Track changes of data? if we talk about Web API there is the @odata.etag property that you can use, or you move to the more generic "modifiedon" field that gives you the last timestamp the record was modified.

    hope it helps

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!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans