Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

By | May 8, 2019

Introduction

PowerApps is a data platform that provides rapid application development environment to build custom apps for your business needs.

In PowerApps you can only perform operations such as create, update and delete. However, to perform more operation you can go for other options such as Microsoft Flow etc.

In this case we created an application named Lead Management for Dynamics 365 CRM to perform certain operation on lead. We were able to access, create, update and delete the lead related data but could not qualify the lead. Qualify is the action in Dynamics 365 CRM to generate Opportunity, Account and Contact from the lead. So for this action we used Microsoft Flow to qualify the lead.

Solution: – In order to qualify the Lead in Dynamics 365 CRM we can use CRM Web API Request through Microsoft Flow to perform this operation.

Step 1

Create new canvas Dynamics 365 CRM app. You can find more about canvas app from here.

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Step 2

Select data source as Lead.

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Step 3

Step 2 will build new mobile application for you which would be having three screens

  • Brows Screen1
  • Detail Screen 1
  • Edit Screen 1

Select the Detail Screen 1 (name can be changed) and from the insert tab go to icon and put a new icon on the action bar as below. We have used an Arrow Icon.

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Step 4

Go to the Action Tab select flow and create new Microsoft flow that will bring you in the

Microsoft flow app.

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Step 5

Add New Step in the flow and select http request and give name as per your choice. We have named it as Request Token. In this step we are obtaining the access token that can be used to execute the QualifyLead Web API request.

Here we are using the Application User which is non-licensed to generate the Access token. As a prerequisite you must perform the below steps;

  • First we have to register an Application on the Azure Active Directory. For more information click here.
  • Then create Application user on the Dynamics 365 CRM. For more information click here.

From these steps you will get the client id and secret key of your registered application in AAD.

Pass parameter to the HTTP step as below:

Method: – POST

URI: – https://login.microsoftonline.com/00000000-0000-0000-0000-000000000000/oauth2/token

<This is the OAuth 2.0 Token Endpoint>

Headers

  • Accept : application/json
  • Content-Type : application/x-www-form-urlencoded

Body

  • grant_type=client_credentials
  • client_id=<Application Id of registered application in Azure Active Directory>
  • client_secret=<Secret key of registered application in Azure Active Directory>

resource= <crm url> e.g. https://contoso.crm.dynamics.com

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Step 6

In this step we will add a variable to store our Authentication token. Name it as Access Token, type will be String and value = @{body(‘RequestToken’)[‘access_token’]}  or body(‘RequestToken’)?[‘access_token’] 

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Step 7

Now add another http request and set the parameter as below to qualify the lead,

Method: – POST

URI: – https://contoso.crm.dynamics.com/api/data/v9.1/leads(⁠<Lead id will be passed from PowerApps>)/Microsoft.Dynamics.CRM.QualifyLead

Headers:

{

“Authorization”: “Bearer <Put the Access Token Variable>​”,

“Accept”: “application/json”,

“Content-Type”: “application/json; charset=utf-8”,

“OData-MaxVersion”: “4.0”,

“OData-Version”: “4.0”

}

Body:

{

“CreateAccount”: true,

“CreateContact”: true,

“CreateOpportunity”: true,

“Status”: 3

}

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

The complete flow will look as follows;

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Step 8

At last go to PowerApps and set the triggering point of the Microsoft Flow on select of the Arrow Icon and pass the lead id to the Microsoft Flow. You can get Lead id from the Browse Gallery’s selected record. This will give you current selected lead record. The formula will be as follows;

QualifyLeadbutton.Run(EncodeUrl(BrowseGallery1.Selected.Lead))

Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

Conclusion

There is no direct method in PowerApps to perform special operations. But, by using Microsoft Flow we can authenticate to CRM Web API and perform special operations or request like WinOpportunity, QualifyLead etc.

4 thoughts on “Qualify Lead in Dynamics 365 through the Canvas App with Microsoft flow

  1. Shubhanker Agarwal

    The step 7 for the http stage does not match the final images under ‘it should look like this’
    Please could u clarify which one is correct. Should it be a POST method or Get method.

  2. Nikita Singla

    I got this error:
    “An error occurred while validating input parameters: System.ArgumentException: Stream was not readable.\r\n at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)\r\n at System.IO.StreamReader..ctor(Stream stream, Encoding encoding)\r\n at Microsoft.OData.JsonLight.ODataJsonLightInputContext.CreateTextReader(Stream messageStream, Encoding encoding)\r\n at Microsoft.OData.JsonLight.ODataJsonLightInputContext..ctor(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings)\r\n at Microsoft.OData.Json.ODataJsonFormat.CreateInputContext(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings)\r\n at Microsoft.OData.ODataMessageReader.ReadFromInput[T](Func`2 readFunc, ODataPayloadKind[] payloadKinds)\r\n at Microsoft.Crm.Extensibility.ODataV4.CrmODataActionPayloadDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)”

    1. Inogic

      Hi,

      The possible cause for this issue could be the wrong property name.

      For example – Instead of customer_account@odata.bind , you have used customer@odata.bind.

      Please check all properties and if everything seems fine then check whether your environment connection or your selected entity is correct.

      Hope this helps.

      Thanks!

Comments are closed.