Use PowerApps as FrontEnd channel & Portal for Dynamics 365 CE on-premise through WebAPI calls - step by step

Hello,

Welcome to another journey in Microsoft Ecosystem, fasten your seat belt and enjoy !


I am going to describe step by step implementation following scenario in the lab study;


Overview
Audience condition : It is expected to have familiarity with Dynamics 365 CE entity model, WebAPI, openAPI, JSON, HTTP, Power Platform, MVC patern and asp.net.

Requirement: A solution of mine requires portal capabilities to meet business requirements so First of all, I need to implement Survey to the solution by generating dynamic questionnaire based on model. I chose PowerApps to generate pages based on design in Dynamics 365 CE. Customers may have n type surveys per customer group to collect feedback.

Dynamics 365 CE on-premise has necessary model for Survey - 8 custom entities are defined for survey like questions, responses, choices etc. -

Architecture :  I have Dynamics CE 365 on-premise engine 9.x at my end and PowerApps free account at Microsoft Azure. A Canvas Application of mine in Power Platform @ Microsoft Azure cloud will reach survey models at Dynamics 365 CE at my end then generate necessary forms dynamically to display to the customer then will send the result back to Dynamics 365 CE to store all survey related records.

Let's start from lowest level from overview;

1- Dynamics 365 CE on-premise engine 9.0 is installed to Windows Server 2016

2- A Survey solution is created on Dynamics 365 CE on-premise

3- A WebAPI type of ASP.NET Web Application (.NET Framework) - C# project is created in Visual Studio 2019 to expose survey entity models and operations to the internet, means make Dynamics 365 CE accessible from Power Platform (I do not use CRM database but only Organization.srv of Dynamics 365 CE as a Data Source for Power Platform).
Each survey related entities will have a specific controller at the Custom WebAPI layer and they will accept requests for get, put, post operations from Power Platform.

4- Microsoft On-Premises Data Gateway is installed in order to build up a HTTP based secure channel between Microsoft Azure and Dynamics 365 CE on-premise (Please look at below for how to install and configure)

The on-premises data gateway acts as a bridge to provide quick and secure data transfer between on-premises data (data that isn't in the cloud) and several Microsoft cloud services. These cloud services include Power BI, Power Apps, Power Automate, Azure Analysis Services, and Azure Logic Apps. By using a gateway, organizations can keep databases and other data sources on their on-premises networks, yet securely use that on-premises data in cloud services.

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/gateway-reference

5- Setting up Microsoft On-Premises Data Gateway application creates Gateways on Power Platform poratl (You need to sign up a account to utilize the power platform)

6- In order to define openAPI for powerAps, Custom Connection for the Gateway as described just above must be created so Custom Connection will decsribe schema of our WebAPI.

A custom connector is a wrapper around a REST API (Logic Apps also supports SOAP APIs) that allows Logic Apps, Microsoft Flow, or PowerApps to communicate with that REST or SOAP API. These APIs can be:

Public (visible on the public internet) such as Spotify, Slack, Rackspace, or an API you manage
Private (visible only to your network)

7- Connection must be created for Custom Connection as a driver to be called by any Canvas Application as a Datasource.

Your canvas app's data connection can connect to SharePoint, SQL Server, Office 365, OneDrive for Business, Salesforce, Excel, and many other data sources.

8- Develop your Power Apps by using Connection to reach out Dynamics 365 on-premise. I developed a survey portal which retrieves survey type, questions, groups, choices etc from Dynamics 365 CE and push back what customer fills.


Step By Step instruction of each steps above;
1- Out of scope, just google it to find lots of screenshot with proper instruction
2- out of scope, use google: how to create custom solution in Dynamics CRM Engine
3- Sample code is at my github page : https://github.com/TheMaty/SurveyWebAPI
4-  Microsoft On-Premises Data Gateway Guide
a- Download the app from https://powerapps.microsoft.com/en-us/downloads/

Screen 1 - Microsoft On-Premises Data Gateway Download
b- Double click GatewayInstall.exe to start installation

Screen 2 - Open File

c- Select installation path and accept terms of use then click "Install" to continue.

Screen 3 - Directory selection to be installed and Privacy Statement acceptance
d- Click "Yes" for Micrososft.PowerBI.DataMovement.UnblockEnterpriseGatewayyInstall User Account Control

Screen 4 - User Account Control

e- Click "Yes" for On-Premises Data Gateway User Account Control

Screen 5 - User Account Control
f- Wizard starts installation of the 2 components respectively.

Screen 6 - Installation Progress
g- Once it is completed, Wizards is going to start installing "Enterprise Gateway Configurator" so Click "Yes" to User Account Control.

Screen 7 - User Account Control
h- Installation wizard will open configuration section after installation. Type email address of your PowerPlatform account.

Screen 8 - SignIn to Power Platform
i - Login to the platform.

Screen 9 - Sign In
j- Your are redirected to the federation services for successfully login.

Screen 10 - Forwarding 
k- Type E-Mail address and Password of your account.

Screen 11 - oAuth Provider
l- After successfully login to the power platform, Wizard will forward you to the Gateway configuration section. Type a Name for On-Premise Gateway and Recovery Key - Recovery key is a minimum 8 characters any text - keep it store for future - then click"Configure".

Screen 12 - Gateway creation 
m- Wizard will complete operation and open post-configuration screen, click Close to complete section.

Screen 13 - Status

Screen 14 - Service Settings 

Screen 15 - Diagnostics 

Screen 16 - Network

Screen 17 - Connectors 

Screen 18 - Recovery Keys 
n- connect to https://powerapps.micrososft.com to login with the credential of what you used above.

Screen 19 - Find gateway in the portal 

6 - Custom Connector Guide
a - go to powerapps portal then find Custom Connectors from the tree view under Data leaf in the left section.

Screen 20 - Custom Connector
b- Click "New Custom Connector" from + sign right top of the page then choose "Create from Blank"

Screen 21 - Custom Connector Creation 

c- give a unique name for the connector

Screen 22 - Type Connector Name 
Note : Name must have less than 30 characters

Screen 23 - Maximum length control

d-  Wizard will open configuration page if the Custom Connector

General Tab: Set Icon, Description, Target End point definition (IP address or CNAME (highly recommended) )

Screen 24 - General Tab 

Security Tab: I created WebAPI without setting Authentication so Local IIS is set for Anonymous.

Screen 25 - Security
Definition Tab: We need to define the get operation to exists in the WebAPI. If you download solution file from Github page of mine , you will see that There is GetSurvey() method underneath so we can define it as below;

Screen 26 - Get method Definition 
The structure of Request must be defined in the form. Thee is an utility to help us : "Import From Sample", just click + add set Get method with header and JSON body. Swagger will help us to generate all automatically.

Screen 27 - Request Definition 

We need to define response of WebApi with columns name.
Screen 28 - Response 

Click "default" to see details if you use Swagger editor to generate all.

Screen 29 - Response Definition 1
Screen 30 - Response Definition 2
Test Tab: In order to perform test and see the result, We have to create custom connector.
Screen 31 - Save Custom Connector for Testing
After record creation, We have to already create connection, Power Platform will ask to create connection at the same window. Just type a name for the connection to be used by PowerApps

Screen 32 - Connection Creation
7- Connection: System will create connection in the platform at Custom Connector

Screen 33 - Connection Section 
8- Convas PowerApps: Create application on power platform as usual just bind connection as data source . Power Platform UI will list connection to use.


Screen 34 - A sample Canvas Application fetching data from Dynamics 365 CE on-premise 

It is very easy :)

enjoy...


Comments

Popular posts from this blog

Complex Query in QueryExpression in Microsoft CRM 2011

Exception caught instantiating TERADATA report server extension SQL Reporting Services

Microsoft Power Apps Portal integration with Dynamics 365 CE On-Premise - Step By Step Guide