Dynamics CRM Tips: Strategy For Fail-Proof Data Model

The rise of JSON (JavaScript Object Notion) is so massive and unstoppable. Just last week, on Twitter, I saw this:

JSON format made it possible to do dynamics coding and hassle-free. On the other hand, how we (in the Dynamics CRM world), rely on the persistent data model and of course, the implementation of the managed solution makes it hard to change if we already deployed it into the production environment (The best practice of it is using the managed solution. I don’t want to make war in this area. 😂). So how can we make our data-model more fail-proof? Of course, the answer is: we can implementing JSON also in our environment.

Common Scenario

A lot of the common scenarios that I encountered were implementations of Status changes (can be: Reserve, Cancel, etc) on a Custom Table (entity). Many people achieve this scenario using boolean attribute like below picture:

Instead of create multiple boolean field, using single-text more recommended

Then in the plugin/workflow/flow, they will check on that field changes to trigger the next action.

I do more like to create a single-line of text data type as a trigger point (for example we named it Operation). For a simple scenario like the above, we just need to set Operation=”Reserve” to triggering the Reserve Action. And of course, as the old saying said to not reinvent the wheels! Don’t forget to change the Status/Status Reason columns as the value that we need it rather than creating other attribute to store.

For the more complex scenario, sometimes we do not just need an Action string. We also want to pass more value that maybe we take from another process result. For example, we want to pass multiple values like this:

    "operation": "Approve",
    "TotalAmount": 1000,
    "Approver": "Manager"

We can use JSON format text and in our backend, we can consume this JSON text via Custom Workflow/Plugin/Flow. Here is sample of code how to consume it:

public class JsonModel
        public string Operation { get; set; }
        public decimal TotalAmount { get; set; }
        public string Approver { get; set; }

    public class SampleBusiness : OperationBase<Entity>
        public SampleBusiness(ITransactionContext<Entity> context) : base(context)

        protected override void HandleExecute()
            var operation = Get<string>("new_operation") ?? "";
            if (string.IsNullOrEmpty(operation)) return;
            // Convert the string to JSON Model data type
            var jsonModel = operation.FromJson<JsonModel>();
            if (jsonModel.Operation == "Approve")
            // Other business logic..

For using JSON in the plugin, we can serialize/deserialize it using this method at this link. For the Microsoft Flow, of course, we can use the OOB function using Parse JSON Action that you can see the sample in here.

The Benefit

Like I said before because saving some of the data (especially related to the programming stuff) using JSON format will help us a lot if someday the implementation needs to change. We just change the JSON format and it is done (of course the action also needs to be re-adjust).


If you have a scenario whereby you want to save the value in JSON format, you can try this PCF JSON Form. For more detail on how to use it, you can check the GitHub project at this link.

PCF Form demo

If you also want to try to implement the Dynamics CRM plugin framework that already had the functions to serialize and deserialize the JSON format, you can check Niam.Xrm.Framework in here.

What do you think?

2 thoughts on “Dynamics CRM Tips: Strategy For Fail-Proof Data Model

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.