Design a site like this with
Get started

Understanding Client API Objects

Microsoft has provided an API facility for retrieving the data from the form directly using web-resource(JavaScript/HTML etc) which is known as Client API.

Client API helps us in many ways like:

  1. Get or set attribute values.
  2. Show and hide user interface elements.
  3. Reference multiple controls per attribute.
  4. Access multiple forms per entity.
  5. Manipulate form navigation items.
  6. Interact with the business process flow control.

Client API has 4 main objects:

  1. Execution Context
  2. Form Context
  3. Grid Context
  4. XRM object

I will be covering the two most used object in this blog which is Execution Context and Form Context.

Execution Context: executionContext defines the event (OnLoad, OnSave, OnChange) on which your code is executed. It passes the runtime information about the event which took place on the forms or grids like user information, form level information, attribute level information etc. It is used in the function as a object which gets all the necessary information from the CRM to our code . Therefore it is required to pass execution context as a first parameter inside the event handler.

function OnContactLoad(executionContext)

Form Context: formContext is a part of executionContext. It provides us an access to a form or form items using JavaScript. Before D365 v9.0 we were using XRM.Page which performed the same role as formContext. With the v9+ of CRM when XRM.Page is being deprecated hence it is always recommended to use formContext.

For accessing formContext below is the command:
var formContext = executionContext.getFormContext();

function OnContactLoad(executionContext)
var formContext = executionContext.getFormContext();

formContext contains two object:
Data object: This used to get the attributes data from the form.
Example: We have a text field on the form and we want to access the field data, then we will be using data object.

UI object: This is useful when we want to hide any control or disable any control.
To know more about controls I would recommend to go through Microsoft documents on Controls.


Introduction to an API

What is an API?

API is the acronym for Application Programming Interface, it acts as an intermediary between two application.

Connectivity is a very amazing thing. In today’s world we are very much habituated to instant connectivity across the globe. Ever thought about how does the data travel from one place to another or from a device to an application.
Each time we use any online shopping site or our phone to check weather or Facebook we are using an API.

In a layman’s term an API acts as a messenger, which takes the request from a user and inform the system what a user wants to do, and return the response back to the user.
Example: When you would go to a restaurant you would look into the restaurant menu and place an order to a waiter of the restaurant. The waiter is the person who would take your order from your table to the kitchen where your order would get prepared.

In the above example the waiter acted as a critical link between your order to the kitchen and deliver your food back to your table.
That’s how an API works. It acts as a messenger which takes your request to the system (in our case its kitchen) which tells the system what to do and deliver the response back to you (in our case its the food.)

Now let’s understand the API in a more realistic way. Most of us might have booked a movie ticket using an app or a website. Let’s take an example of BookMyShow app, this app helps us in booking the movie tickets online. Any thought how does the app gets you the movie timing and the tickets fares from different multiplex/malls which are currently running which show. Yes, its the API which play a very important role, the unsung warrior of our connected world.

I would say API acts as an engine who plays a very important role behind the scene, because of API only it is possible to get what we expect and rely upon.

Hope now you are clear with what is an API and its use.

Microsoft Release 2020: Email Enhancement

Microsoft has come up with enhanced email feature in 2020 release wave 1 plan.

Let’s take a closer look into CRM, how the email functionality used to work before enabling the Enhanced Email feature.
User clicks on email activity from timeline, CRM would navigate the user to Email activity screen.

Now, Let’s enable the Enhanced Email feature.

  • Steps to be followed are:
  • Go to Sales and click App Settings
  • Manage Enhanced Mail option would be available
  • Enable Enhanced Email
Figure 3: Enabled Enhanced Email and Hit the Save button

Going back to the Sales. Refresh the browser to get the changes reflected when user click on Email Activity being within any entity.

Figure 4: Now email activity got opened in a separate dialog.

We still get the ability to work on Account form though New Email form is being populated on top of it.

Hope this blog helps in understanding this feature.
Happy D365 CRM

Generate Auto Number for entity without code in D365 CRM

We all know that Microsoft has the auto-number feature, but it has its own prefix for auto-number and its own sequence for generating auto number.
There are many ask from the users that the auto number for an entity should have their org name as a prefix and the random number should be in a particular format.

Today, let’s learn how to implement the auto-number functionality for an entity with the prefix required by business user.

Before we start we should have D365 System Admin rights with us.

Login to D365 CRM online and Navigate to Power Apps portal.
Below is the Power Apps Home page. Click on Data, which gets expanded and show us the entities currently present under the logged in CRM Instance.

Figure 1: Power Apps Home Page

Select the desired entity, I am selecting Account entity.

Figure 2: Select Account entity

The below tabs under the yellow box are the one from where we get to know about the Fields, Relationship, Business Rule, Views etc. present under Account entity.

For achieving the Auto Number functionality, we will create a new field by clicking on “+Add field” button.

Figure 3: Entity details and adding new auto number field

Provide Display name to the field and change the datatype to “Autonumber”.

Then let’s change the value under “Autonumber type” field to Custom. Under Format field we can use custom auto number format.

Seed value is by default 1000, we will be using the same.

Depending on the combination of Format and Seed field. We get the sample output under Preview.
Now, hit the “Done” button.

Figure 4: Create Auto-Number field

Click on Save Entity.

Figure 5: Save the changes done on entity

Now, let’s navigate to our CRM screen and open the Account entity under customization where we can decide where to place the newly created autonumber field (Acc Account Number) on the Account Form and Publish the change.

Figure 6: Field placed on the form, hit the save and publish button.

Going to Account entity and creating a new account. When clicking on Save, we get to see that a random auto number got populated under the Acc Auto Number field.

Figure 7: Auto Number generation

Hope this helps you. Enjoy D365 CRM!

Microsoft Release 2020: Open dialog on button click

Today, we will see how to open an entity main form on top on another entity main form without navigating from one entity to another.

Let’s take an example of Order and Product entity. So, when a user clicks on Order entity main form ribbon button then Product entity main form dialog should get pop up above Order entity main form instead of navigating to Product entity.

Steps to achieve the above functionality:

  • Get the Ribbon Workbench solution installed on the CRM instance.
  • Create a new solution and add Order entity.
  • Create a new web-resource of JavaScript type and add the below JS code in it.
  • Add the web-resource in the solution.
function DialogPopUp()
pageType: "entityrecord",
entityName: "product",
formType: 2
target: 2,
position: 1,
width: {
value: 70,
unit: "%"

Now, lets open the solution inside ribbon workbench.
Click on Open Solution button on the left top this with pop up a window. Using which we get the ability to select the desired solution which we want to open inside ribbon workbench.

Figure 1: Ribbon Workbench

Drag the Button option from ToolBox menu and place it on the Order form ribbon. Rename the button by inserting a new name in the Label. I have given Product Dialog – the same would get reflected on the Order main form.

Figure 2: Create button on Order entity

Now create a new command by clicking on the “+” icon. This is where we call the JavaScript webresource as shown in the below image and provide the JS function name(DialogPopUp) inside the Function Name field.

Figure 3: Create a new command for calling JS webresource

Enable the Display Rule to True. For this click in the “+” icon next to Display Rule and

Figure 4: Enable Display Rule

Select the button rule as shown in the below image and tag the command inside Command drop-down.

Figure 5: Tag command inside Command drop-down

Now, we need to save our changes therefore hit the Publish button. Post that go back to Order entity and refresh the browser.

Figure 6: Product Dialog button on Order entity.

Hit the Product Dialog button and we should get the Product entity main form on top of SalesOrder entity.

Figure 7: Product Dialog on SalesOrder Entity

Happy CRM!

Microsoft Release 2020: Open Dialog on Lookup field click

Normally, we have observed that whenever a user clicks on any lookup field value. Then the CRM navigates the user to the lookup entity record page.

Today’s we will learn how to stop user from navigating from one page to another page on click of lookup field value. This will help users to have a good experience while using CRM product and increase their productivity on their day to day activity on CRM.
This, will actually reduce the number of click which users makes while navigating from one entity to another entity main form and coming bank again to the main form page.

Let’s take an example of Account entity, when a user go to account entity they may have multiple lookup fields on the Account Main form. Clicking on the lookup field value user gets redirected to the lookup associated entity record. Today’s blog is related to the same scenario where when a user clicks on lookup field value, a dialog should open on the same main form instead navigating the user to another entity main form.

Steps to implement the Lookup dialog functionality and let’s take an example of Account entity.

  • Create a new Javascript web resource.
  • Add the web resource under Account Form libraries.
  • Then call the web resource function (LookupDialog) on the Account entity Form: OnLoad event.
  • Publish the changes.

Below is the code which you can use for achieving lookup dialog functionality. I have made it generic so that the same code can be used for any entity main form OnLoad event.

This feature is achievable with the help of OnLookupTagClick Event.

//Call function onload of form with execution context passed.
function LookupDialog(executionContext)
var formContext = executionContext.getFormContext();
//Get all attributes on form on event. (attribute, index)
//For each attribute check whether the attribute type is "lookup" or not.
var attributeType = attribute.getAttributeType();
var attrName=attribute.getName();
//If attribute is of lookup type, add OnLookupTagClick event to field

function OpenLookupDialog(formContext,lookupField)
formContext.getControl(lookupField).addOnLookupTagClick(context => {
const lookupTagValue = context.getEventArgs().getTagValue();
pageType: "entityrecord",
entityName: lookupTagValue.entityType,
formType: 2,
target: 2,
position: 1,
width: {
value: 70,
unit: "%"
Figure 1: Adding Web resource on entity OnLoad event

Post publish –> Go back to the Account entity UCI form and refresh the page.

Figure 2: User click on Primary Contact which is a lookup field.
Figure 3: Contact main form opened on top of Account form.

Now, we have managed to stop the CRM from redirecting us to the lookup record page. Indeed we get the dialog on top of the page we were residing.

We also get the ability to maximize the dialog width to full screen. The option appear in the above picture under the green box. Once the dialog is maximized to to full screen we will still have the “X” icon on the screen. It will allow us to come back directly to the Account main form.

Note: This feature would work only on the UCI form not on Classic form.

Happy CRM! 😊