Embed Microsoft Forms in your website and get leads in Dynamics 365 CRM without writing code

 

Introduction

We come across frequent requirement where customers ask to create a custom page and embed it in their website and write logic to get leads into Dynamics 365 CRM.

In this blog, I have explained how without coding we can achieve this requirement.

Approaches

Traditional Approach

We will create custom HTML page and create custom service hosted somewhere and then using JavaScript we will make a call to the web service and create respective records in CRM.

Alternative Better Approach

We can use Microsoft Forms & Microsoft Flow and without coding we can get the lead data inserted into Dynamics 365 CRM.

How-to Steps

Pre-Requisites:

  1. You should have D365 CRM (Sales) license.
  2. You should have access to Microsoft Forms (refer References section for the same).
  3. You should have access to Microsoft Flow.

Create Microsoft Form to get Lead Information

  1. Login to https://portal.office.com and open Forms from Admin Center.

1

  1. Click on New Form

2

  1. Name the form and keep adding questions.

3

  1. This is my form

4

  1. Click on Share option and select Embed option.

5

  1. Copy the Iframe tag and include it in your web page.
  2. That’s it. Your form is ready.

Create Microsoft Flow to insert response in Dynamics 365 CRM.

  1. Go to Flow from admin center.

6

  1. Select CREATE FROM BLANK option. Give some name to Flow.
  2. Search for Microsoft Form in connector and select Microsoft Forms – When a new response is submitted

7

  1. Select your form.

8

  1. Click Next step and select Add an Action.
  2. Search for Microsoft Forms and select Microsoft Forms – Get Response Details
  3. In the configuration put below formula as per below screenshot.

first(triggerBody()?[‘value’])?[‘resourceData’]?[‘responseId’]

9

Refer this blog to understand above formula.

  1. Click on Next step and select Add an Action.
  2. Search for Dynamics 365 and select Dynamics 365 – Create a new record (V2)
  3. Select Organization.

10

  1. Select entity as Leads. It will show the fields of Lead entity as below.

11

  1. Click on Last Name textbox and select Last Name option from the right pane as per below screenshot. Repeat same steps for other fields.

12

Note: Click Show advanced options to see optional fields.

  1. That’s it. Finally click on Create Flow.

At this stage you are ready. You can start entering data in your form and it will automatically get inserted into Dynamics 365 CRM near to real time.

References

  1. Know more about Microsoft Forms

https://forms.office.com/

https://support.office.com/en-us/forms

  1. Frequently asked questions about Microsoft Forms

https://support.office.com/en-us/article/Frequently-asked-questions-about-Microsoft-Forms-495c4242-6102-40a0-add8-df05ed6af61c

 

Advertisements

Invalid stage transition. Transition to stage {0} is not in the process active path.

Introduction

With latest release of Dynamics 365, Microsoft has restricted skipping BPF stages and throws above error. When we try to change BPF stage programmatically and if we skip any BPF stage, then user will get above error.

Understand the error with the help of an example

Let’s say we have below Business Process Flow on Opportunity.

sample BPF

With D365, only below transitions are allowed.

  1. Qualify to Develop
  2. Develop to Propose
  3. Propose to Close

Below transitions are not allowed.

  1. Qualify to Propose
  2. Develop to Close
  3. Qualify to Close

How my earlier code (prior to D365 release) worked and suddenly stopped working?

Before D365 release by Microsoft, the above scenarios were considered as unsupported and there were no restrictions forced by Microsoft. Hence our code used to work in these unsupported scenarios as well. With D365 release, Microsoft has restricted these unsupported scenarios and users will start receiving the error with same code.

How have I come to this conclusion?

  1. I got the error log file with error code and same error code (-2146885629) is now available in SDK (you can search in CHM file).

SDK Error Code

  1. I raised a support ticket with Microsoft and as per confirmation from MS Support, it has turned out to be by-design. I received below response from MS Support Team.

Reply from MS Support

Note: Even though Microsoft has mentioned Environment as CRM Online, as this is by-design in D365, it applies to CRM On-premise deployments as well.

Summary/Resolutions

  1. After thinking about these unsupported scenarios, it makes sense to use logical branching to skip the stages if needed and if not, then we should follow the path mentioned in BPF.
  2. The resolution to this issue can be programmatically iterate the record through all the stages or use conditional branching in BPF.

How to use Business Rules to determine Form Type in Dynamics CRM

Introduction

One of the frequent requirement we receive is doing basic form customizations based on Form Type. E.g. Show few fields while creating record and hide those fields once record is saved.

First option which comes in developer’s mind

As we cannot check entity’s form type using Business Rules, we must use JavaScript to achieve this requirement. Hence, usually developer will write a JavaScript method and register an event on Form Load.

This will be time consuming task as compared to the solution which I have explained below. Also, it will need technical person to achieve this requirement, because it involves coding.

An option that usually skips from developer’s mind

As we know, Created On field is populated only when record is created. Also, CRM does not allow to set Created On field to the user, we can take help of this field to determine whether user is on Create form or has opened existing record.

Below screenshot shows how Business Rule can be configured to unlock the Account on Create form and lock it for existing record.

business rule

Simple solution, but we usually miss it.

How alternate key is useful while importing data into CRM?

Introduction

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.

Customers

1

Contacts

2

  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.

3

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.

4

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

5

NOTE: IF WE DON’T RENAME THE COLUMN, IMPORT WIZARD WILL NOT SHOW FIELD MAPPING WINDOW AND WILL DIRECTLY START IMPORTING THE DATA AND EVENTUALLY WILL RESULT IN FAILURE.

  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.

6

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

7

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

Introduction

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?

Introduction

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.

dataset-fields

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

query-designer-output

  • 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:

tablix-sorting-configuration

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

Introduction

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

data-flow-how-to-send-ssrs-in-pdf-format-in-email-in-crm-online

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: https://msdn.microsoft.com/en-us/library/dn481600.aspx

  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 Xrm.Page.data.entity.getId() 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();

    retrieveEntityReq.open(“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.

    retrieveEntityReq.send(query);

    //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();

    retrieveEntityReq.open(“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.

    retrieveEntityReq.send();

}

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

References

  1. Create Email and Attachment in CRM using C#

https://msdn.microsoft.com/en-us/library/hh210217.aspx

https://msdn.microsoft.com/en-us/library/gg328344.aspx

  1. More about Actions in CRM

https://technet.microsoft.com/en-us/library/dn531060.aspx

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

 generate email with pdf attachment code snapshot