How alternate key is useful while importing data into CRM?


In this blog, I have explained how an alternate key column can be used to import the data into CRM using OOB import/export facility.

We get frequent requirements to perform initial data load for customers and contacts. In almost all cases, we are asked to link the Contacts to the customers.

This can be achieved easily using Alternate Key in CRM.

In this blog, I have assumed that we have Account Number field as an alternate key on Account entity and Contact Number (custom field) as an alternate key on Contact entity.

How to achieve this?

Case 1 (initial load): We have 2 separate Excel/CSV files as per below screenshots.





  1. We will first import the data of Account (as it is straightforward I have not explained about it in this blog).
  2. Then we import the contacts. This is also straightforward except one below check in field mapping.
    1. In field mapping we have to select the Account Number as a matching field for Company Lookup field.


Case 2 (Update existing data): Now we have contacts with accounts selected, on Accounts we need to select primary contact.

Let’s say we have below CRM view and we click on Export to Excel and put the contact numbers appropriately in Primary Contact column in Excel.


If you note in below screenshot, I have renamed Primary Contact field to Contact Number which contains Contact Numbers.



  1. Now we save the exported Excel with contact numbers and start data import with the same file. It will again give similar field mapping dialog where we have to select Contact Number as a matching field for Primary Contact field.


  1. After completing import wizard steps, you will see the result as below:



Understanding organization’s base currency in Dynamics 365 (CRM)


In this blog, I have explained what should be the base currency of an organization and what problems you may encounter if you do mistakes in selecting it.

What is organization’s base currency?

Organization’s base currency is the currency which is selected at the time of installing D365 On-Premise or while configuring D365 Online.

Where currency is used?

All entities in CRM have a lookup reference to Currency entity. This lookup reference determines the currency in which all the Currency type fields should be captured for a record. E.g. On opportunity record, we have a lookup to Currency entity i.e. we select currency on the opportunity record. So based on selecting the currency on opportunity all its currency fields like Est. Revenue, Total Amount, Discounts are captured.

What is _base field which gets created for each currency type field?

If you have observed, when we create a field of type Currency, its corresponding _base field is created automatically by CRM. This field always gets calculated in Organization’s base currency.

How multiple currencies work and how the exchanges rates are applied?

When you install the CRM, by default it enables only single currency which is considered as organization’s base currency. The Exchange rate of Base Currency is set to 1 and we cannot change it.

When we add new currency (from Setting > Business Management > Currencies), we select the currency code and put Exchange rates which are corresponding to the base currency. These exchange rates are used later while calculating base amounts.

How to capture/update exchange rates and how it impacts existing records?

Exchanges rates in CRM are not captured automatically. You will need to manually put exchange rates either at the time of enabling currency or update it later in existing currencies.

When we update exchange rates in CRM, it does not apply to existing amounts of the existing records. When any amount field gets updated on existing records, the updated exchange rates are used to calculate base values.

Understand with examples

Let’s say, we have below setup in our CRM Environment.

Organization Currency: US Dollar (USD)

Additional Currencies:

  1. Indian Rupees (INR) with Exchange Rate: 1 USD = 68.03 INR
  2. Australian Dollar (AUD) with Exchange Rate: 1 USD = 1.39 AUD

Below table contains examples of quote records with different combinations of currencies.

Quote ID Currency selected on record Total Amount

(captured using currency selected on record)

Total Amount _Base

(captured using organization’s currency)

DLKJ548 INR INR 158900 USD 2336.18
KEIK902 USD USD 59800 USD 59800
PELJI7453 AUD AUD 6500 USD 4681.88


Unforeseen problems which might occur later

  1. Organization’s base currency can be selected only at the installation/configuration time of CRM. We cannot change base currency once CRM is installed/configured.
  2. Sales goals are always captured in organization’s base currency. We cannot change currency on Sales Goal record.
  3. If you select base currency incorrectly, then for reporting purposes, you might always need to convert the amounts in your currency using exchange rates.

Case studies

Case 1

Contoso is Indian company which works on Indian Rupees currency. All the clients of this company are Indian clients and they don’t have any other clients from other countries.

Solution: In this case, only single currency is needed which will be organization’s base currency i.e. Indian Rupees (INR).

Case 2

Contoso is Indian company which works on Indian Rupees currency. This company has clients across globe like US, Australia, New Zealand etc. The company has 85% clients from US and remaining 15% customers are distributed among other countries.

Solution: Even though, the company has 85% customers from US, and no customers from India, the company works on Indian Rupees currency. Hence, the organization’s base currency should be set to Indian Rupees (INR) and additionally USD, AUD, NZD currencies should be enabled with their respective exchange rates.

Case 3

Contoso is Indian company which works on US Dollar currency. This company has clients across globe like US, Australia, New Zealand, and India etc. The company has 85% clients from India and remaining 15% customers are distributed among other countries.

Solution: Even though, the company is Indian company and has 85% customers from India, the company works on US Dollar currency. Hence, the organization’s base currency should be set to US Dollar (USD) and additionally INR, AUD, NZD currencies should be enabled with their respective exchange rates.

How data can be sorted on date field in SSRS report in Dynamics CRM?


This is a short and simple article which explains how we can avoid sorting issues on date field in SSRS report in Dynamics CRM Fetch Based report.

Understanding Concepts

  • When we write fetch based SSRS report for Dynamics CRM, for complex field type, we always get 2 attributes in SSRS dataset. E.g. Lookup, Option Set, Date and Time, Currency etc.
  • From above 2 attributes, one contains the display string and other contains data value.
  • In Case of Date and Time field, as per below screenshot, we got 2 attributes in SSRS dataset for Est. Close Date field which is of type Date and Time.


  • If you run the simple query (FetchXml of Open Opportunity view) in Query Designer, you will see data in below way.


  • As we have display data and value data in separate field, for display purpose we should use display field (estimatedcloseddate in this case) & for data manipulation we should use data field (estimatedclosedateValue in this case).

How to sort data in Tablix based on date field?

  • As we have seen above how the dataset contains the data, we have to select data field in sorting expression to sort the data in required order.
  • To achieve this, go to Tablix properties and Sorting section and configure as per below screenshot:


Note: The Order (A to Z / Z to A) is just to determine Ascending or Descending order. It does not mean we have to provide only string type fields in Sorting Column. SSRS understands the data type and sorts the data accordingly.

How to send SSRS report as a PDF in Email in Dynamics CRM Online


In this blog, I have explained how to create an email record in CRM by executing SSRS report and exporting as a PDF attachment to the email. This is frequently asked requirement by many clients and it is very simple to execute SSRS report and export as a PDF in CRM Online.

In this blog, I have kept focus on generating PDF format report using coding. I have also provided the code of generating PDF format report. I have not covered creating email record with attachment and reference links from this blog can be used to achieve the same.

Problem Statement/Assumptions

  1. We have a CRM Online environment with below things setup.
    1. Fetch based SSRS report with name let’s say ‘Quotation.rdl’.
    2. Assume, Quotation.rdl has below GUID.
      • 12f3c105-fd95-44a9-b1af-ad79dfe3ad16
    3. Quotation report is pre-filtered by Quote GUID. (What is pre-filtering?)
    4. On Quotation entity, we have a button called Send Quotation.
      • The purpose of this button is to execute SSRS report, Export it as a PDF, Create Email record with above generated PDF as an attachment & open Email record on successful completion of above operations.

Data/Events flow


Step-by-step procedure

  1. Create an action in CRM on Quote Entity.
    1. Input Parameter: PDFString (String type)
    2. Output Parameter: EmailID (EntityReference to Email entity)
    3. Create email record in action definition.
  2. Write a plugin on above custom action that will read input parameter which is a string that contains base64 formatted SSRS report. Create an attachment using the string and attach the same to email.

To know more about actions in CRM:

  1. Create a web resource with below JavaScript code (Code has the commenting to understand the code).

function sendQuoteAsPDFInEmail() {

    //1. Execution starts here.

    var arrReportSession = executeReport(); //2. Execute the ssrs report and capture the response. Response will be an array.

    convertResponseToPDF(arrReportSession); //3. Convert the response in base 64 string i.e. PDF.


function executeReport() {

    // GUID of SSRS report in CRM.

    var reportGuid = “12f3c105-fd95-44a9-b1af-ad79dfe3ad16”;

    //Name of the report. Note: .RDL needs to be specified.

    var reportName = “Quotation.rdl”;

    // URL of the report server which will execute report and generate response.

    var pth = Xrm.Page.context.getClientUrl() + “/CRMReports/rsviewer/QuirksReportViewer.aspx”;

    //This is the filter that is passed to pre-filtered report. It passes GUID of the record using method.

    //This filter shows example for quote report. If you want to pass ID of any other entity, you will need to specify respective entity name.

    var reportPrefilter = ”                      “;

    //Prepare query to execute report.

    var query = “id=%7B” + reportGuid +

        “%7D&uniquename=” + Xrm.Page.context.getOrgUniqueName()

        + “&iscustomreport=true&reportnameonsrs=&reportName=” + reportName

        + “&isScheduledReport=false&p:CRM_QuoteId=” + reportPrefilter;

    //Prepare request object to execute the report.

    var retrieveEntityReq = new XMLHttpRequest();“POST”, pth, false);

    retrieveEntityReq.setRequestHeader(“Accept”, “*/*”);

    retrieveEntityReq.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);

    //This statement runs the query and executes the report synchronously.


    //These variables captures the response and returns the response in an array.

    var x = retrieveEntityReq.responseText.lastIndexOf(“ReportSession=”);

    var y = retrieveEntityReq.responseText.lastIndexOf(“ControlID=”);

    var ret = new Array();

    ret[0] = retrieveEntityReq.responseText.substr(x + 14, 24);

    ret[1] = retrieveEntityReq.responseText.substr(x + 10, 32);

    //Returns the response as an Array.

    return ret;


function convertResponseToPDF(arrResponseSession) {

    //Create query string that will be passed to Report Server to generate PDF version of report response.

    var pth = Xrm.Page.context.getClientUrl() + “/Reserved.ReportViewerWebControl.axd?ReportSession=” + arrResponseSession[0] + “&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=” + arrResponseSession[1] + “&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF”;

    //Create request object that will be called to convert the response in PDF base 64 string.

    var retrieveEntityReq = new XMLHttpRequest();“GET”, pth, true);

    retrieveEntityReq.setRequestHeader(“Accept”, “*/*”);

    retrieveEntityReq.responseType = “arraybuffer”;

    retrieveEntityReq.onreadystatechange = function () { // This is the callback function.

        if (retrieveEntityReq.readyState == 4 && retrieveEntityReq.status == 200) {

            var binary = “”;

            var bytes = new Uint8Array(this.response);

            for (var i = 0; i < bytes.byteLength; i++) {

                binary += String.fromCharCode(bytes[i]);


            //This is the base 64 PDF formatted string and is ready to pass to the action as an input parameter.

            var base64PDFString = btoa(binary);

            //4. Call Action and pass base 64 string as an input parameter. That’s it.



    //This statement sends the request for execution asynchronously. Callback function will be called on completion of the request.



  1. Register a JavaScript action on button that calls ‘sendQuoteAsPDFInEmail’ method.
  2. That’s it.


  1. Create Email and Attachment in CRM using C#

  1. More about Actions in CRM

  1. Snapshot of code to generate Email record with PDF from base64 string.

 generate email with pdf attachment code snapshot

Relevance Search is Next Generation Search


In last release Microsoft introduced Next Generation Search (AKA Relevance Search) as a preview feature. In the latest release, i.e. November 2016 update, Microsoft has made this feature generally available. In this blog, I have covered this feature in detail.

Types of search

With relevance search, CRM now have 3 types of searches.

  1. Quick Find View – This search is restricted to particular entity. This is the basic search available since CRM 4.0
  2. Categorized search – This search was introduced in CRM 2015 release and is also known as global search. It searches the data across multiple entities using entity’s quick find view and shows the data categorized by particular entity.
  3. Relevance Search – With relevance search, you will get the results which are relevant to the search terms you are searching for. Relevance search will not be restricted to any entity type or any field, but it will search based on the relevance to your search terms.

What is Relevance Search?

  • Relevance search delivers fast and comprehensive search results based on the relevance across multiple entities.
  • It uses dedicated search service provided by Microsoft Azure which is external to Dynamics 365.
  • With relevance search, you can still use the other two types of searches.
  • Below are the benefits and enhancements provided by relevance search:
    • As external search service provided by Microsoft Azure is used to search the data, search performance is improved drastically and search is performed outside the D365 environment.
    • It uses semantic searches hence results may include inflectional words like win, won or winning, etc.
    • It returns results with matching the search term in any words and in any field in the entity.
    • The result is not categorized by the entity type, but it is returned and sorted based on the number of words matched and how the words are related to each other.
    • In the results, the words which are matched are highlighted.


  • Relevance search is not available for D365 On Premise environments.
  • There is no limit on number of entities you can search, but there is a limit of 1000 index you can have per organization. While configuring entities for relevance search, you can see how many indexes are needed to enable the respective field and entity.
  • As relevance search is hosted on Microsoft Azure cloud platform, any changes to the data in D365 environment takes 15 minutes to get synced with Azure Search. Also, for average to large data it takes an hour or more to complete the full sync between D365 environment and Azure Search Service.


  • Below fields are not supported for relevance search:

Find Fields

  1. Lookup
  2. Option set
  3. Rollup & Calculated fields
  4. Non-text

View Fields

  1. Lookup
  2. Option set
  3. Fields of related entities

Filter Fields

  1. Lookup
  2. Option set
  3. Fields of related entities

How Relevance Search makes a difference?

  • In quick find view search, i.e. entity level search, when user searches for a phrase, it tries to search all the sentence exactly in the fields of the entity and if all the words matches then only it returns the result.
  • In categorized search, i.e. global search, it also gives same result as quick find view, but it searches across the entities and maximum entities which can be searched is 10.
  • In relevance search, individual word from the search phrase is searched across the entities and in all the fields. The more relevant results are shown first. The relevancy is decided based on the number of words matched against the searched data and how close the words are to each other. For e.g., if the search term is found in an address and in an article, then result with address will be considered as more relevant data than the article.
  • There is no limit on how many number of entities you can search using relevance search.

How to configure relevance search?

Configuring relevance search is 3 steps process. First you need to enable the relevance search and then enable the entities which should be involved in the relevance search, and at last you need to configure the fields which should get included in relevance search.

Step 1: Enable relevance search

  1. You need to have system administrator/customizer role on D365 environment.
  2. Go to Settings > Administration > System Settings.administration_system-settings
  3. In General section, you will see an option as Enable Relevance Search. Select Yes and click OK on the popup shown.
  4. Once you enable the relevance search, it becomes your default searching option and can be changes later to categorized search from your personal settings options.

Step 2: Enable entities for relevance search

  1. Go to Settings > Customizations > Customize the System.
  2. Under components, expand Entities, and click on Configure Relevance Search option.configure-relevance-search
  3. Select the entities and click okay. Publish all customizations.

Note: If you want to include any entity for relevance search, then below highlighted managed property of the entity should be set to True.


Step 3: Enable fields for relevance search

  1. Go to Settings à Customizations à Customize the System
  2. Go to Quick Find View of an entity for which you are configuring the relevance search.
  3. Select the find columns for the entity. By default, the fields you add in find columns of quick find view become part of relevance search. There is no limit on maximum number of fields allowed, but as explained earlier, there is limit on number of indexes involved in relevance search.

How to use relevance search?

  • Once you enable, relevance search becomes your default search. Just like global search, you can start searching your data and it will return data using relevance search.
  • As you can see in above image, on left side you can filter the records and also select any particular record type to reduce your result set.
  • You can easily switch between relevance search and categorized search.swith-between-searches

Difference between Relevance Search & Categorized Search with few examples

  • Below screenshot shows my available data:


Case 1: I search for ‘need 110 item’ term.

  • Relevance search returns below datacase-1-1
  • Categorized search did not return anythingcase-1-2

Case 2: I search for term ‘ 10 items + need’

  • Relevance search returns below datacase-2-1
  • Categorized search did not return anything



Know more about relevance search

Learn how to search data with relevance search to get accurate data

D365 New Features – Editable Grid (Part 2)


In first part of this blog, I have explained features of Editable Grid which is introduced in latest release of MS Dynamics 365. In this blog, I have explained how to configure editable grid and how it can be used.

How to configure editable grid

Read-only grid

  • By default, when you create any custom entity or any OOB entities, editable grid is not configured.
  • By default, read-only grid is shown to the users.
  • You cannot disable read-only grids on any entity. You can choose which one to show by default i.e. either read-only or editable grid.

Home grid (editable grid)

  • To enable editable grid on entity’s public views, you should add new control in entity.
  • You can enable editable grid on entity’s public views as per below steps:
    1. Go to settings > Customizations > Customize the system.
    2. Expand entities section and click on entity on which you want to enable editable grid. You will see entity’s properties.
    3. Click on Controls section.
    4. By default, you will see below screen (if editable grid is not enabled).
    5. Click on Add Control
    6. Select Editable grid and click add.
    7. You can select which grid to be shown as a default grid for an individual entity.
    8. Select additional settings like filtered lookup properties to filter lookup values in editable grid. Follow below steps to achieve the same:
      1. Select Editable Grid control as selected in above screenshot. You will see below options to set properties of editable home grid.
      2. Click on Add Lookup (Note: It allows to filter lookup values which will be populated in editable grids lookup field. If your view does not contain any lookup field, then you won’t see anything here).
      3. Set the necessary options and click OK.
    9. Save the changes and publish the customization.

Sub grid (Editable Grid)

  • To enable editable grid for sub-grids, you need to add new control on entity form.
  • You can enable editable grid for sub-grid by following below steps:
    1. Open form editor of entity’s form on which you want to enable editable sub grid.
    2. Select sub grid control and click on change properties.
    3. Go to Controls Tab. Click on add control.
    4. Rest of the steps are same as I have mentioned above for home grid.

Nested Grid

  • Nested grids are nothing but grid within grid. Nested grids are available only on Mobile & Tablets.
  • Nested grid can be enabled on Home as well as sub grids.
  • To enable nested grid, follow below steps:
    1. Follow similar steps as mentioned earlier to enable editable grid.
    2. Select Editable Grid and you will see an option to set properties for Nested Grid.
    3. Click on the pencil icon and select the entity and to be shown in nested grid. Select the parent lookup field on which the related records should be fetched.
    4. Save and publish the changes.

Dashboard Grid (Editable)

  • Dashboard editable grid is available only on mobile and tablet devices.
  • Follow below steps to enable editable grid on dashboard:
    1. Open dashboard in design mode.
    2. Select component and click on Edit Component.
    3. Go to Controls Tab and Add control.
    4. Follow the same steps as mentioned above.

How to add event handlers on editable grid events

  • Adding event handlers is similar as we used to do for adding event handlers on form fields.
  • You should navigate to Events tab and follow same steps as we used to perform earlier:
  • For Home grid, you should navigate to Entity’s design page.
  • For sub-grid, you should navigate to property page of sub grid.
  • For dashboard grid, you should navigate to dashboard grid’s property page.

How to use Editable Grid

  • Once grids are enabled for inline editing for home grids, you will see a new option in ribbon as ‘Show As’.
  • If you have put Read-only grid as default grid, you can select any of the option. Read-only grid will show the old views.
  • If you select, Editable Grid, you will see below options.
    1. Group By – Users can group by columns. So, if you have option set on any entity and you want to see all records grouped by individual values of option set, you can select the same in Group By drop down.
    2. Filtering the records – You can still filter the records by clicking an down arrow which is shown on each column’s right side.
    3. You can click on the column to sort either in ascending/descending order.
    4. You can drag-drop the column to see important information at the start at your convenience. Below screenshot is taken when user is dragging the Account Name column after Main Phone column.
    5. Saving the record – As I mentioned in earlier blog, records get saved automatically when focus is moved from the record. Also, users can explicitly save the changes by clicking save option provided on right corner of the grid.
    6. Editing the records – The UI of editable grid is so intuitive, that users come to know whether the field is editable or locked. Also, you can easily navigate to the lookup record by clicking arrow. Refer below screenshots.

Some additional information

  • Editable grid also works on same security model. i.e. if user does not have write access on the record, then editable grid does not allow users to update the record.
  • Field level security works in same way in editable grid as well.

D365 New Features – Editable Grid (Part 1)


Finally, most awaited feature has arrived in Microsoft’s Dynamics 365 business apps solution (formerly known as Dynamics CRM). Microsoft has introduced Editable grids in their latest release and new era called Dynamics 365. I am publishing this blog in 2 parts. In this part of blog, I have focused on what is Editable grid, what are its features. In next part of this blog, I will be covering how to configure the grid and how it can be used.

What is Editable grid?

Before release of D365, users needed to open the existing records to update any data in the entity. Even if users want to update single field in multiple records, they had to open the individual record and update the field and save the record. For each record, they had to repeat these steps. This approach of updating data was time consuming and irritating.

With introduction to editable grid, Microsoft has allowed users to update the records right away with all those validations which was applicable on the form.

Editable grid is nothing but a list or view of records having editing capabilities without opening the record.

Editable Grid Features

Types of grids

  1. Read-only grid – These are the same grid which users are seeing in earlier versions. The CRM entity views which do not have editing capabilities are called read-only grids in D365 release.
  2. Home grid – These are the CRM entity views having editable grid capabilities. Entity’s public views and personal views with editing capabilities are called home grid.
  3. Sub grid – This is old grid which is shown on entity form to show related records. Sub grids can also be made editable.
  4. Nested grid – This is new grid introduced in D365. Nested grids are shown when we expand any record in view itself without opening form. This grid also shows related records of expanded record from view.

Note: Nested grid is available only on Mobile and Tablets. It is not available on web client/CRM for Outlook.

  1. Dashboard grid – This is the grid which is shown on CRM dashboards.

Note: Dashboard grid is available only on Mobile and Tablets. It is not available on web client/CRM for Outlook.


  1. Below types of fields have inline editable grid capabilities:
    1. Single line of text
    2. Date and Time
    3. Option Set
    4. Whole Number
    5. Decimal
    6. Floating Point Number
    7. Two Options
    8. Lookup
  2. Below types of fields are read only in editable grid:
    1. Customer
    2. Rollup Fields
    3. Calculated Fields
    4. Composite Fields
    5. Status and Status Reason Fields
  3. Business rules which are have scope at Entity level works on editable grids.

Note: Business Recommendations (introduced in this release) is not available on editable grids.

  1. Below JavaScript events are available on editable grid:
    1. On record select
    2. On save
    3. On change
  2. Users don’t have to explicitly click on save button. Records are saved automatically when focus from the record is moved.
  3. As its name suggests, only inline editing is possible and users cannot create records through inline editable grids. Users can still use quick create form to quickly create the records.
  4. Below grid functionality is available for editable grids:
    1. Sorting
    2. Searching
    3. Grouping
    4. Filtering
    5. Pagination
    6. Column resizing
    7. Column movement by simply drag and drop capabilities
  5. It also saves user state within the session. So, if user does any settings like column resizing, column movement on active accounts view, and if user navigates to any other entity, then when user comes back to the active accounts view within the same session, it shows the same settings.
  6. The editable grid is nothing but an additional control and can be exported through a solution and imported back into target environment as a solution.