Tuesday 31 October 2023

CALLING A MICROSOFT FLOW FROM DYNAMICS 365 AND POWERAPPS USING JAVASCRIPT

 

CALLING A MICROSOFT FLOW FROM DYNAMICS 365 AND POWERAPPS USING JAVASCRIPT


In our previous post, we send a POST request to a Microsoft Flow. We showed how to do this using the Postman application. Let’s now run this from Dynamics 365 / PowerApps.

On our Account page, we have a field called Partner Ranking. We see the ranking for the current account is set to 7:

Now let’s say we want to post a message to a Microsoft Teams channel when this number drops below 5 for an account. We want to do this using JavaScript on saving of the Account record.

First, let’s create a new Flow. Go to https://flow.microsoft.com: and select New->Instant – from blank:

Let’s call it “Post to Teams” and select When an HTTP request is received:

You will see below. Click on Use sample payload to generate schema:

We will send account and ranking to our teams chat message, so let’s create a JSON sample with these 2 fields:

{
  "account": "testaccount",
  "ranking": "0"
}

Paste this into the window and click Done:

We see the schema has been generated from the sample JSON payload: Set the method to POST:

Now let’s add an action, search for Teams then Post a message:

 

Select the Team, Channel and Message. We will use Dynamic content – account and ranking – in the body of our message. Click Save:

This generates a URL for our HTTP POST to hit. Copy the URL:

Now let’s customize Dynamics 365 / PowerApps. Go to Customizations for the Account entity and find the field name. In https://make.powerapps.com/ we see the field is adx_partnerranking and the account name is name:

Now let’s go into the main Account form:

Switch to Classic and go to Form Properties:

Let’s Add a new script:

Click New:

We will call it CallFlow.js and set it to JScript:

Now the JavaScript code. We will get the ranking and account values from the form using getAttribute, and paste the url from our flow copied above into the url variable. The code posts to the address the JSON data we have created if the ranking is below 5:

function PostFlow(executionContext) {

var formContext = executionContext.getFormContext();

var ranking = formContext.getAttribute("adx_partnerranking").getValue();
var account = formContext.getAttribute("name").getValue();

if (ranking <= 5) {
  var req = new XMLHttpRequest();
  var url = "<paste url from flow>";
  req.open("POST", url, true);
  req.setRequestHeader('Content-Type', 'application/json');
  req.send(JSON.stringify({
    "account": account,
    "ranking": ranking
  }));
 }
}

Click Save and click Add:

In Form OnSave click Add:

Select the JS library and enter the PostFlow function we created:

Save and publish the form:

We’re now ready to run our test. Go to the Account form and change the Partner Ranking field to 4:

On saving the record, we see the Flow is run through JavaScript and a teams chat message is created with “Partner ranking for account 3M is 4”:

That’s it, you can now run Microsoft Flows from Dynamics 365 and PowerApps using JavaScript.

Wednesday 25 October 2023

SETTING UP POWERAPPS CANVAS WITH DYNAMICS 365 DATA

 

SETTING UP POWERAPPS CANVAS WITH DYNAMICS 365 DATA

In a rapidly evolving world of how data is collected and processed, Microsoft has focused on a multitude of strategies to assist organizations to stay ahead of the curve. One such approach is the “Low code – No code” technology that empowers functionally oriented power users to build quality applications that can help rapidly adapt to the changing business requirements. PowerApps as a part of Microsoft’s Power Platform has been widely acknowledged as the leader in this market segment.

PowerApps is an application with services, connectors, and a data platform that provides a rapid development environment for constructing custom apps for business needs.

Apps built using PowerApps:

  • Enable users to build feature-rich, custom business apps with no or minimal code (everyone is a Programmer – wink wink).
  • Provide rich business logic and workflow capabilities to transform manual processes to digital, automated processes.
  • Have a responsive design allowing the apps to run seamlessly in a browser or on mobile devices.

PowerApps has four major components:

  • Canvas apps start with the user experience, creating a highly tailored interface with the power of a blank canvas and connecting it to your choice of 200 data sources. One can build canvas apps for web, mobile, and tablet applications.
  • Model-driven apps start with the data model – building up from the shape of your core business data and processes using the Common Data Service to model forms, views, and other components. Model-driven apps automatically generate great UI that is responsive across devices.
  • Portals start to create external-facing websites that allow users outside of your organization to sign in with a wide variety of identities, create and view data in Common Data Service, or even browse content anonymously.
  • Common Data Service is the data platform that comes with PowerApps and allows users to store and model business data. It is the platform on which most Dynamics 365 applications are built.

This article will primarily focus on how to set up a canvas app and connect it with Dynamics 365 data.

Initially, a user will be required to possess the prerequisite licenses and security access in order to reach the PowerApps resources.

Sign into https://make.powerapps.com/

PowerApps dashboard

Click on Connections from Data -> Connections

powerapps connections

Then click New Connection and select the Dynamics 365 for Fin & Ops option and click create.

powerapps dynamics 365 fin ops connector

A prompt to authorize connection to the Dynamics 365 connector will appear and once credentials are verified, the connection will be created. Please note that the credentials used must also have the requisite security privileges on the Dynamics 365 environment as well.

Next, Click create and select the start from data canvas app option.

data canvas app powerapps

In the next pop-up window select the new connection that was created earlier and choose the specific environment to connect to and the table.

dynamics 365 powerapp connection

This example will connect to the employees table to create a basic employee directory.

employees table basic employee directory

PowerApps should then auto generate the app and the content based on the data source and it’s built in algorithms.

autogenerated powerapp

To make this app functional, some tweaks need to be completed so that the necessary information for the directory app will be displayed correctly.

Click on Browse Gallery on the left pane and then click edit on the right pane’s Fields option to change the displayed info to the requisite fields.

browse gallery powerapps

Upon selecting the right fields, we can proceed to go into the Detail Screen and see if the information there matches requirements. If not, select the detail form element and edit he fields to include the necessary ones.

powerapps tree view

Next, review the code for the search box to ensure the searchable fields are correctly set up.

review code powerapps

Finally once all the necessary changes are made, proceed to preview and test the app on the browser to confirm all the requirements are met and then save and publish to your organization’s environment.

Git Basic working

  Develop = dev   r