web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Conditional update of a record through Web Api

(0) ShareShare
ReportReport
Posted on by 5

Hello everyone :) 

I have the following situation:

- There are many instances of a service that is updating records in Common data service (Dynamics 365 CE (CRM)) through the Web Api. Lets call the service the Updater.
- The Updater is subscribed to a topic and listening for update messages.
- The messages with data to update have their own IDs, the ID is incrementing number, so message with ID 13 will contain newer data than message with ID 12, for example.
- It may happen that these 2 messages arrive at the same time, and both are handed by different instances of the Updater, and so it is possible that message with older data is handled after one with newer data (the one with ID 12 after the one with ID 13), overriding newer data with older.

I was looking for solution to disallow/block update operation on Common data service's end when the custom ID field (a number) of the record to update is newer then the one in the update message. Also I'd like to avoid the usage of a plugin/CWA in this case.

Are there any goodies in CDS/Dataverse that would allow us to perform such conditional operation - update the record only in case the ID field in the call is greater then the one in the database?

Any suggestion is welcome! :) 

I have the same question (0)
  • Guido Preite Profile Picture
    54,086 Moderator on at

    as I understood you are just trying to avoid a read operation of the record to verify the data before the update, correct?

  • draghetto Profile Picture
    5 on at

    Yes, read operation won't help as both instances may perform it at the same time, both will see that the ID in CDS is 11 (as per the example above), both will try to update at the same time, but it may happen that update call with ID 13 (newer data) arrives earlier than update call with ID 12 (older data). Both will update the record, but we won't have the latest data in CDS.

  • draghetto Profile Picture
    5 on at

    So no options in CDS/Dataverse to allow us to update the record only in case the ID field in the call is greater then the one in the database and to block in other cases?

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    not by an out of the box feature. the quickest way will be probably to write a plugin (sync pre-operation) with a pre-image triggered on the update event.

    inside the plugin you will check if the value of this ID field is greater than the existing one, if is not greater your plugin will throw an exception.

    From a web api update call the operation will simply fail if the ID is not greater and will be completed if the ID is greater.

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans