Hello everyone, we are back again with a new hot topic i.e. integrating dynamics AX 2012 with Power Apps, for that we will go through the following steps:
1-Creating a custom service in Dynamics AX and deploying it on AIF inbound port.
2- Creating an ASP.NET application (Web API) on Visual Studio to consume AX custom service.
3- Generating swagger definition for our ASP.NET application (Web API).
4- Configure IIS and adding our ASP.NET application on it.
5- Making inbound rule on Windows Firewall for our ASP.NET application port on which it is running in IIS.
6- Forwarding port on router to expose our application port on internet.
7- Adding Custom connection in Power Apps for Dynamic AX 2012.
8- Making application on Power Apps Platform using our custom connection.
1-Creating a custom service in Dynamics AX and deploying it on AIF inbound port
First we would create a custom service which would retrieve customer names from CustTable, for that select class node of AOT and create a new class and set its properties as following:
Add a method to our service class and type the following code as shown below, compile the method as it will be our service operation.
Select the Service node of AOT, create a new service and set its properties as below. Note that the class property is initialized with the service class that we had recently created.
Expand our newly created service node named AXPCustomerServiceDemo , right click on operation node and select add operation. A window will open with class method, tick the check box and select ok, a method will be added to the operation node of our service.
To deploy our service on AIF Inbound port we would create a Service Group for that select ServiceGroup node of AOT and create a new service group, named it as AXPCustomerServiceDemoGroup, right click on it and select add node reference and set its properties as following:
Right click on our service group i.e. AXPCustomerServiceGroupDemo and select Deploy Service Group and now go to System Administration from AX rich client select inbound port under AIF Integration Service, you will found that your service group has been activated with the same name that that you had given to it and ready to be used for communication with any external application.
Copy the WSDL URI as we will use it in our second step.
2- Creating an ASP.NET application (Web API) on Visual Studio to consume AX Custom Service
Open Visual Studio 2015, Select New Project, create ASP.NET Web application, named it as ASPCustomerApp and click OK.
In the next window select Web API as it would provide restful CRUD operations which would be useful in case of Power Apps as it only understand JSON as rest API.
Select Change Authentication Button and choose No Authentication option as we don’t want any kind of authentication in our application. Finally click OK.
In Solution Explorer right click on References and select Add Service Reference.
A window will appear, here in Address paste WSDL URI of your service port that you had copied earlier and press GO. The Services and Operations windows will populate with your service and operations. Name service reference as CustomerServiceReference and click OK. Your service will be added in Service References with the same name in Solution Explorer.
In the Solution Explorer expand Controllers and double click on ValuesController.cs file and modify the code in it as below:
3- Generating swagger definition for our ASP.NET application (Web API)
Now the step we are doing is really time saving as you don’t need to learn swagger to document your API, we will add a powerful tool to our application which will document our Web API in JSON format as we need to do in swagger editor after learning swagger but don’t worry as alternate of everything is available in this world of technology.
In your ASP.NET application Go to Tools>NuGet Package Manager>Package Manager Console and type the following command in the Package Manager Console and hit enter:
We are almost done with our application. Now just run your application and see the magic in browser by adding few parameters to your application link and hit enter as shown below:
You will see that a page is open with JSON for your API on it. Copy it and then navigate to http://swagger.io/swagger-editor/
Paste your JSON in the editor, click on the File and click Download JSON.
Your Swagger file will be downloaded, rename it as CustomerNames and along with it download AX 2012 icon or any other icon that you want to upload with your swagger file as we will make Custom API on Power Apps for the bridge connection between Power Apps and Dynamics AX 2012.
4- Configure IIS and adding our ASP.NET application on it
For IIS configuration press windows key, type Turn Windows features on or off in the search bar and hit enter, a window will appear with multiple features, find Internet Information Services and check the following boxes as shown in the screenshot below then finally click OK.
Copy your ASP.NET Application folder to the following path as shown below:
Open Internet Information Services (IIS) Manager, Right click on Sites and select Add Website, a window will appear as shown below. Fill out the following information as it is and press ok.
Once you successfully add your website then move on to Application Pools, select your website in there and go to Advance Settings as highlighted in the screenshot below:
Select identity and replace ApplicationPoolIdentity by pressing a box containing dot dot, select custom account then press set button and provide your windows credentials to avoid Dynamics AX 2012 login issues when running your application on the port that you had selected for your website and finally press OK. You are all set now, select your website and click browse on the right to test that your ASP.NET Application is running as it was on visual studio when you run it.
5- Making inbound rule on Windows Firewall for our ASP.NET application port on which it is running in IIS
We would now make inbound rule on firewall for our application port to allow all incoming traffic from internet on it, for that open Windows Firewall and go to Advance settings, click on Inbound Rules and click New Rule on the right, a windows will appear as shown below, select Port and click Next button.
In the Specific local ports option enter the port number on which your website is running in IIS Manager and click Next button.
Select Allow the connection option and click on Next button as shown below:
Check all three options in the next window and click on Next button as shown below:
Finally give name to your newly created inbound rule and click on Finish button, you will found that inbound rule has been created and activated in Inbound Rule list.
6- Forwarding port on router to expose our application port on internet
Now it’s time to play with our router to tell it that if any request came for our website from internet so redirect it on this port as our website is available on it. For that first you need to find your local ip address and default gateway address to access your router. Open Command Prompt and type ipconfig, IPV4 Address is your local ip address and default gateway is the address to your router copy and paste it on your browser and hit enter, a login screen for your router will appear, type user name and password and then press login. In my case user name and password are both admin.
A below screen will appear for your router configuration, Go to Forwarding in the left pane and select –Virtual Servers then press Add New button.
In the below screen enter your port number, your local ip address and leave the other option as they are. Click Save button and you are all done with port forwarding.
7- Adding Custom connection in Power Apps for Dynamic AX 2012
Beginning with this step, first we would find our public ip address and then edit our swagger file. For finding your public ip address go to Google, type my ip in the search bar and hit enter. Copy your public ip address and edit your swagger file by just replacing host value with this public ip and save your swagger file. Now your swagger file and icon are ready to upload on Power Apps. Open https://web.powerapps.com, sign in with your Power Apps credentials, In the left pane select Connections, On the top right select New Connection, select custom option, on the top right select New Connection, upload your swagger file, icon image and fill out the following information as shown below and click on Next button:
In the next screen click on Create button and then you will find your Dynamics AX 2012 connector created in custom connections as shown below:
8- Making application on Power Apps Platform using our custom connection
Now we will design an application on Power Apps web platform, to do so select New app button on bottom left of Power Apps web service, a window will appear as shown below, select PowerApps Studio for web.
In the next window, select Phone layout in Blank app option.
Now Power Apps designing platform will appear for designing our application with few tools and tricks but before that we need some data to populate our app. In our case data source for this application will be the same AX 2012 connector that we had uploaded recently in Custom API tab. We would begin with a layout, for that on the layout pane select second layout and you will see the layout will be inserted in your blank app.
To use Dynamics AX Connector in our application so that it could bring data from Dynamics AX 2012, click on Data Sources option just below layout pane, select New Connection and choose DynamicsAX2012R3 from the list of connector then finally click Connect.
Now that the data source has been added to your app, just click on gallery of your app and type the following in the formula bar ASPCustomerApp.ValueGet().
What you will see that a list of customers from Dynamics AX 2012 CustTable will be displayed here in the gallery of your application, now just press F5 and view your application in preview mode as shown in the screenshot:
I hope that this blog will be really helpful for all developers of Dynamics AX 2012 who want to communicate their external application on Power Apps with AX 2012. So stay tuned, we will be back with new topic in Microsoft technological world, Thank you.