Prevent Data loss/Duplicates Using Concurrency Behavior In Dynamics CRM

This blog is just a reference to very important article on dealing with a problem when two or more update or delete operations on the same piece of data happen at the same time. This situation could potentially result in data loss.

Explanation : Reduce potential data loss using optimistic concurrencyReduce potential data loss using optimistic concurrency.

Sample Code : Use optimistic concurrency with update and delete operations

Get User’s Teams Using WebApi JavaScript In Dynamics 365

If you need to get current/logged in or of any other user’s all teams. You have to look for the N:N relationship schema name and use that association in WebApi request:


So below is the code you can use to achieve this requirement. I have just retrieving the name of the teams associated and putting an alert on Onload of a form.

I have generated the code using Rest Builder Tool . And added the filter ($filter=systemuserid eq  IdOfTheuser) manually.

function GetUserTeams()
    var userSettings = Xrm.Utility.getGlobalContext().userSettings; // userSettings is an object with user information.
    var current_User_Id = userSettings.userId; // The user's unique id
    var newid = current_User_Id.slice(1, -1);	
    var req = new XMLHttpRequest();"GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/teams?$select=name&$expand=teammembership_association($filter=systemuserid eq "+newid+")", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var results = JSON.parse(this.response);
            for (var i = 0; i < results.value.length; i++) {
                var name = results.value[i]["name"];
        } else {

I am calling the function on Onload event of lead record. My user has two teams associated to it:



Important – Make sure you format the code fully before you use it. i.e use the latest method in the script i.e not using Xrm.Page but rather the formContext for v9.

I hope this helps! Cheers!


Get Selected Record Information From Main View Or A Subgrid In Dynamics 365

I recently had a requirement to get selected record id from a main view of an entity i.e. Home page view of an entity and also on a subgrid within the form.

I also needed to pass this ID to my action to do some further operations in the plugin. This is how I did

I have taken reference from  here  and here.

  1. Download the managed solution of Ribbon Workbench from here and import it to your Dynamics CRM 365 environment:
  2. Create an unmanaged  solution and add contact entity to it. ( I am taking contact entity as I need to perform action on that, you can select any entity)
  3. Create two JPG images web resource with sizes as 16×16 and 32×32 for your ribbon button. You can take the desired image and rescale it online.
  4. Create a javascript web resource and below code to it:
    function GetRecordInformation(item)
        var selectedItem = item[0];
       alert("You have Select Record with Id=" + selectedItem.Id + "\nName=" 
    	+ selectedItem.Name + "\nEntity Type Code=" + selectedItem.TypeCode.toString() + "\nEntity=" + selectedItem.TypeName);
  5. Publish all your customization and open ribbon workbench tool from your solution area and select the solution that you have created and click ok:1.png
  6. Now drag and drop a button to the home grid view:1.png
  7. I have named this button as “SELECT” from the button properties you will get once you add and select the button on bottom right side of the ribbon workbench also select the Image for you button by providing the web resources we created in step 3 :1
  8. Now that out button is ready, we need to add a command and enable rule to it. to do this from the solution component area click on commands and click on + button and then from the right side click on add “Action”  and then click on “Javascript action”:1.png
  9. Add your javascript resource by searching in the lookup, if you dont find the script( i faced the issue). Simply add $webresource:WebResourceName for me its $webresource:new_SelectRecord  
  10. In the next box – add the function name i.e for me its GetRecordInformation
  11. Then click on Add parameter and select SelectedControlSelectedItemReferences Parameter. It should look like below:


  12. The final step is to add an enable rule to this command. To do this – from the solution component area click on Enable Rules and click on + button. On your right side you will be presented with below, Make sure you keep the information as it is:1
  13. We are done , now click on Publish from the ribbon. wait for it to completed as it might take some time. Once done navigate to your dynamics CRM and the main entity home view, you should see the button:1.png
  14. Select a record and click on the button and Bammmm! if everything goes right you will get the record information.1

You can do the same thing on a form subgrid, all you have to do is place the button on a form grid instead of home view.

I needed to further processing with the data so I called an action and passed the record id described here :

I hope this has been helpful!

Make All fields Mandatory/Optional On Form Using Javascript

This should be a very quick blog on JavaScript helper which will let you make all fields on the form mandatory or optional. This requirement is hypothetical; I have not received any till now.

I am going to be calling below function on OnLoad event of the form based on a field value but you can very well call is on OnSave of record, or OnChange event of field.

For Dynamics CRM below v9:

function SetRequiredLevel()    
  var attributes =;
    for (var i in attributes) {

For Dynamics CRM v9 or above use below and make sure pass the context as first parameter ( checkbox) on the form editor while calling the function.

function SetRequiredLevel(executionContext)    
  var context = executionContext.getFormContext();
  var attributes =;
    for (var i in attributes) {



1. If you need to check some value you can do that i.e.

If ( fieldAValue = 1)

//the above code goes here//


2. If you have to make fields optional rather then mandatory , do this:

I hope this helps!!

Quick Note: Dynamics 365 CE Limitations


I often find myself struggling to get collated information on limitations on number of different component you can create in dynamics CRM.

I researched and found below link very useful, could not re-blog hence sharing them here. full credits to the owner of this content.

Dynamics 365 CE Limitations On Technet

Limitations On Creating CRM Metdata

If you don’t find anything related to Business Process Flow & Alternate Key Limitations :

  • There can be no more than 10 activated business process flow processes per entity.
  • Each process can contain no more than 30 stages.
  • Multi-entity processes can contain no more than five entities.
  • There can be a maximum of 5 alternate key definitions for an entity

Reference : Business Process Flow Overview  & Define Alternate Keys

Please note – It is strictly applicable to Dynamics CRM 365 Online, May or May not be true for other versions.

Please feel free to comment down below if you know any other limitation on any component in dynamics CRM.


MB2-877 Field Service Exam Retiring…….

As we all know or for those who are not aware, Microsoft plans to restructure its certifications path due to which below dynamics CRM certification are going to retire:

Retiring on April 30, 2019

  • MB2-715 Microsoft Dynamics 365 customer engagement Online Deployment (originally published Feb. 24, 2017)
  • MB2-717 Microsoft Dynamics 365 for Sales (originally published Feb. 21, 2017)
  • MB2-877 Microsoft Dynamics 365 for Field Service (originally published Dec. 8, 2017)

If you have been following my blog , I have been preparing and also creating blog for MB2-877 Field Service exam. However because of this news I have stopped publishing more blogs. I might continue with these blog once we get the updated syllabus from Microsoft. 

Below blogs have been created so far:

  1. Overview
  2. Part -1 
  3. Part -2
  4. Part -3
  5. Part -4
  6. Part -5
  7. Part -6
  8. Part -7
  9. Part -8
  10. Part -9
  11. Part -10
  12. Part -11
  13. Part -12

I will restructure or create content again for this exam once we have updated exam on field service for dynamics crm.

See you soon!

Quick Fix : Mandatory Field Error Shows Schema Name Instead Of Display Name

Quick blog on how to fix the error you get when you save a record which has some required fields on the header of the form and CRM shows the schema name instead of display name like below:


it shows the error which includes specific field logical name instead of display name which might be confusing for user and doesn’t look very much user friendly. In my case its still very much understandable but sometimes people change name on the form and in that case it will be worse situation.


All you have to do is put the same field on the form which is there on the header and hide it on the form. Open the form editor > select the section > look for the field and add it. Go to field properties and hide it by unchecking the visible by default box:


Save and publish all your changes and now try to save the record:


I hope this help!

Get Api Version Dynamically For WebApi Requests

In this post I will quickly cover the requirement of dynamically getting API version of dynamics CRM in JavaScript rather then hard coding it , so that in next releases your JavaScript doesn’t break. I am referring to this:


For Dynamics CRM version 8.2 or below, do this:

var apiVersion = Xrm.Page.context.getVersion();

For Dynamics CRM version 9 or above, do this:

var apiVersion = Xrm.Utility.getGlobalContext().getVersion();


It will give you an expanded version which includes minor and major versions. Now, all you have to do is crop the number to get only initial numbers such as 9.1 in this case:

var shortVersion= apiVersion.substring(3, myStr.indexOf(“.”) -1);

then finally use it in your request as:"GET",Xrm.Utility.getGlobalContext().getClientUrl()+ "/api/data/"+shortVersion+"/systemusers

Hope this helps!

A bit About “Post” In Dynamics 365 CE

What Is It?

Do not get confused between a note & a post, They are two different things. With Posts you can get attention of other users to show some crucial information, they can be auto generated by the system or a user can manually add them. You can do a great collaboration between organisation members using posts. 

On the other hand, Notes are added by a user always and can consist of attachments (posts cannot have attachments).

How to enable post for custom entity OR how to turn on/off post for out of the box entities.

Whenever you create a custom entity a “post configuration” record is created in CRM. for out of the box entities, the post configuration already exists such as opportunity , cases etc.

For any entity (Custom or OOTB) if you have activities/notes enabled; you can have post enabled for it. but for any reason if you dont see it. Go to Settings > Activity Feeds configurations :


look for the entity, i.e in my case I would like to look for contact:


If you don’t see your entity listed here, try to look for it in the “inactive post configurations” view.  Also refresh the feeds from ribbon button, the configuration should appear:


Open the record, you have option to enable it or turn it off:


In my case for my custom entity “Loan” which I have enabled post but those were not appearing on the wall & all i was seeing is Activities and Notes:


So I followed steps mentioned above , went to Settings > Activity feeds configurations > couldn’t see the entity > clicked on refresh button and then I could see the entity and it was in inactive status:


LEARNING : For a custom entity by default the posts are in inactive status & has to enabled manually:

So I opened it,  activated it and enabled for the wall: 


Make sure you publish the related entity and then open the record, you will the post has been enabled:


That’s for this blog – I will try to cover few important features of post in dynamics CRM.