Restrict data overwrite in crm 2011

The CRM applications being open for multiple users to access, there arises a rare situation where two or more users are accessing the same record.

Also in such cases, there can be a requirement to let users work on latest information only. Specially in case when users can edit same attribute for same record from multiple locations. This is important when such shared data need to be protected from being overridden.

Below steps although might not be a good standard for a client-server architecture, but gives a control for supporting the rare requirement of having a record version:

  1. Customize the entity for which this behavior is required and add hidden attribute e.g. ‘passKey’ which will store a unique number whenever the record is refreshed.
  2. Mark its submit mode as always so that it will be pushed for all updates.
  3. Register a (post operation create & update) plug-in to store a random number as a passkey in this attribute. This plug-in will be a key generator for generating such passkeys.This passkey will be treated as a key for a user in update operation later.
  4. Register a (pre operation update) plugin to check for the latest passkey value for the current record. This can be done by having an image to load the latest record version. It is recommended not to have all attributes in the image as it could increase its size substantially.
  5. Allow update operation only if both passkeys are matching else operation could be stopped throwing an exception with a nice friendly message which will ask user to refresh the form as it is a older version now.
  6. This still holds true at attribute level as well, if versions to be avoided for complete entity. Just that passKey generation will happen only if the required attribute is updated and not on each entity update.

Use these steps when such requirement is absolutely un-avoidable. Although it is all supported code but the style used is not recommended for many entities at one go.

Happy coding.

This is the first version from my laptop! 🙂