Saturday, July 24, 2021

Call Power Automate From Power Apps Portal

 In this blog , we are going to see how to call power automate from power apps portal.


1. Create Webtemplate to show the existing account information

2. Create Page Template ->Select created web template

3. Create Web page.

4. PowerAutomate to update the changed account in portal.


{% fetchxml acc %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="account">
<attribute name="name" />
<attribute name="primarycontactid" />
<attribute name="telephone1" />
<attribute name="accountid" />
<attribute name="address1_composite" />
<order attribute="name" descending="false" />
</entity>
</fetch>
{% endfetchxml %}
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 80%;
}

td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}

tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<table class="center">
<tr style="background-color:#616A6B ">
<th style="color:white">Account Name</th>
<th style="color:white">Main Phone</th>
<th style="color:white">Address</th>
<th style="color:white">Primary Contact</th>
<th style="color:white">CRM Status</th>
<th style="color:white">Action</th>
</tr>
<body>
{% assign crmstatus = 0 %}
{% for ac in acc.results.entities %}
{% assign crmstatus = crmstatus | plus: 1 %}
<tr>
<td><input type="text" id="{{ac.accountid}}" value="{{ac.name}}"/></td>
<td><input type="text" readonly id="ACCID{{ac.accoundid}}" value="{{ac.telephone1}}"></td>
<td><input type="text" id="AddID{{ac.accoundid}}" value="{{ac.address1_composite}}"></td>
<td><input type="text" readonly id="ID{{ac.accoundid}}" value="{{ac.primarycontactid.Name}}"></td>
<td><span id="{{crmstatus}}" value="crmstatus" style="color:green"></span></td>
<td><button id="{{ac.accountid}}" onclick="updaterecord('{{ac.accountid}}','{{crmstatus}}')" type="button">Update</button></td>
</tr>
{%endfor %}
</body>
</table>
{% raw %}
<script type="text/javascript" language="javascript">
function updaterecord(id , status){
//document.getElementById(id).value = "updating.."
document.getElementById(status).textContent="updating..";
var acupdate ='{ "accountid": "'+id+'" , "name": "'+document.getElementById(id).value.trim()+'"}';
var req = new XMLHttpRequest();
var url ="https://prod-149.westus.logic.azure.com:443/workflows/814110a076614ca1be8b1b3e2f9df1a2/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=ToeEUUGg5s6M5Pq8re5hPGxgwTydIDgP7vzS0MAfefU";
req.open("POST" , url , true);
req.setRequestHeader('Content-Type', 'application/json');
req.onreadystatechange = function() {
if (this.readyState === 4){
req.onreadystatechange = null;
if(this.status === 200){
var results = this.response;
//document.getElementById(id).value = results;
document.getElementById(status).textContent=results;
}
}
};
req.send(acupdate);
}
</script>

{% endraw %}


Power Automate:

1. Choose When http request received
2. Give below sample load request

{
"accountid":"1234",
"name":"myaccount"
}

3. Choose Update row of dataverse
4. Add Http response , give status 200 and body value as "updated !"





















No comments:

Post a Comment