Power Community

Power Community

How to use Power Automate Flow in Power Pages

Introduction

In this blog, we are going to use Power Automate Flow through Power Pages to achieve business requirements. Using Power Automate saves lots of time and is easy to use.

Let’s Jump into the scenario where we are going to create a record of a custom entity named “Policy” which is related to contact through an N:1 relationship. Policy entity consists of Start Date, End Date, Name, and Contact fields. In Start Date, today’s date will be set, and based on how many years the user has taken the policy the End Date will get set.

To create a site using Power Page with the template of your choice, kindly access the following link. For this demonstration, we have configured a public portal that will be accessible to all. You can customize the site according to your business needs, also, you can set the privacy settings as desired. We designed our site as shown in the below image where the First Name, Last Name of the contacts are displayed. There is an input field where users can specify the purpose for taking the policy in the read-only grid and there also are two buttons that allow users to proceed with the policy according to their preferences.

Power Pages

Step 1 – Create a solution from Power Pages -> New -> Automation -> Instant Power Automate flow -> Skip -> Power Pages Connector -> Select When Power Pages call a flow trigger.

Then enter some input variables as shown in the below screenshot

Power Pages

Step 2 – Add a new step -> Choose Microsoft Dataverse Connector -> Add a new row -> Select Policies entity.

And then add the below formulas for the respective fields and save it.

Microsoft Power Platform

End Date: addToTime(utcNow(),int(triggerBody()[‘text_2′]),’Year’)

Start Date: utcNow()

Power Pages

Step 3 – Navigate to Home from Power Pages and then edit the respective Site from the list of Active Sites using the Edit button. Then click on Set Up and Cloud Flows. Then using the Add button add the respective Cloud flows to your respective site.  Select and edit the respective flow, from where you can Add respective Roles and the flow shall run only for the user with the selected role.

Power Pages

Power Pages

Note: Copy and store the URL as it will be used later in the code.

Step 6 – Navigate to the pages -> Added new Page -> Start from blank -> Edit with visual studio code.

Power Pages

Power Pages

Replace the HTML code with the below code. In the below code, we are fetching the contact record. On click of those buttons, we called a function named “CreateRecord()” which is taking parameters contactid and year respectively. When a user clicks on the desired button which is “1 Year” or “3 Year we have passed the number of years respectively i.e., “1” for a one-year policy and “3” for a three-year policy.

Inside the function, we created a data JSON and passed it in the post request for Power Automate Flow which will create the policy record. In the code, we have added the URL which we got in Step 4.

div class="sectionBlockLayout text-left">
{% fetchxml contact %}











{% endfetchxml %} {% if contact.results.total_record_count > 0 %}
{% for contactRecord in contact.results.entities %} {% endfor %}
First Name Last Name Taking Policy For Get Policy
{{contactRecord.firstname}} {{contactRecord.lastname}}
{% else %}

No records found.

{% endif %}

Now visit the site where you can see the below pop-up click on sync and the changes we have made in the code will get synchronized.

Power Pages

After that, you can see the  “No records found” on the web page. But when you will open it in the preview you can see the records as shown in step 1.

Power Pages

Power Pages

After clicking the policy button our flow will be called and the policy record will get created based on how many years the user is taking the policy for.

Power Pages

Conclusion

Thus, we learned how to create a record through Power Automate Flow when we want to create a record using Power Pages with some calculated values and logic.

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

6 User-Friendly steps to connect Dynamics 365 CRM with Mailchimp – Effortless Integration!

As a CRM user, you understand the importance of managing customer relationships effectively. But what about integrating your marketing...

More Articles Like This

- Advertisement -spot_img