Using Logic Apps in Power Automate
Tags: powerautomate, logicapps, powerplatform, lowcode
Published: 2023-01-24 09:21:59

One of the things I love about in Blue Prism are business objects. Business objects are Blue Prisms version of connectors, allowing the process to interact with systems. But what's great about them is they are totally customisable, the developer can either use the Application Modeller or code their own business objects (Visual Basic or C#). Additionally Blue Prism have created multiple out of the box business objects (like Excel), that can be modified for your exact needs.

The real power is these business objects are reusable, so multiple different processes share them, pooling benefits and simplifying lifecycle updates.

Obviously Power Automate is different, it's all API's, so there is no need for business objects, or is there. I would love the ability to create reusable actions, that may not necessarily require an API to work. Let's say you want to do some data transformation from an API response, and every flow that uses it has to use a complex condition and expression logic. How useful would it be to create a reusable function, pass the data in and get it out consistently how you want it.

## Logic Apps

And this is when I had the idea to use a Logic App. Logic Apps and Power Automate are pretty much interchangeable, so in theory you could just use another Flow (http trigger) as your business object, but logic apps have a couple of benefits:

- Better Connectors/Actions
- Authentication can be added
- Logic Apps are better value

**Better Connectors/Actions**
The key action I love in Logic Apps is the script connector. I know Power Automate has Office Scripts, but they aren't as fully functional and have timeout/response size [limits](https://learn.microsoft.com/en-us/office/dev/scripts/testing/platform-limits#power-automate) (120 Seconde/5mb)

**Authentication can be added**
Security are never found of the Power Automate HTTP trigger, as there are currently no security approved way to authenticate access. So the url is open to the web and in theory anyone can call it. Logic Apps can have aad [authentication added](https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-custom-api-authentication?tabs=azure-portal), protecting the API from external calls

**Logic Apps are better value**
Logic Apps, like all Microsoft licenses aren't simple, but are widely considered lower cost (Pay as you go is $0.000025 per action for every execution and charges $0.001 per enterprise connector action execution). Power Automate requires user license, plus $10 per month for premium (HTTP connector is premium), and you are limited to 40,000 Power Platform API calls per day.

---

## Demonstration

So in this demo we are going to do something quite simple, but it's just to show how easy it is (I'm also not going to show the authentication setup, that is a little more complex).

The demo is going to convert csv to array (one of my annoyances with Power Automate, how this is not out of the box is ridiculous). The Logic App will be very very simple, it will just use the one script action and let a few lines of JavaScript do the work.

For a Logic App you need a resource group. From which you need to create a new resource. From the Marketplace search for Logic Apps and select 'Logic App'

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xfmnz9v64kvggft7ewmo.png)

Once the Logic App is created you can select 'Create a workflow in Designer' to start building the Logic App.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3suxrom1ff3guacir5f.png)

In this demo we are using inline scripting, so we will need an Integration Account resource as well. We just need to add a resource and search for Integration Account (good guide [here](https://dotnetthoughts.net/using-excute-javascript-code-action-in-azure-logic-app/)). Else you will get below error:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z3yysdxdwodgh4gt0789.png)

As you can see it's very similar to Power Automate.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1c3yy3wsdnmc3bgqci1.png)

The simple demo takes a string input which is the csv. Uses JavaScript to create a json, and then passes it back

```
var csv = workflowContext.trigger.outputs.body.csv
   csv = csv.replace(/\r/g, "");
  let rows = csv.split("\n");
  let ret=[];
  let firstR=true;
  let header=[];
  const csvRegX = /(?:,|\n|^)("(?:(?:"")*[^"]*)*"|[^",\n]*|(?:\n|$))/g
  rows.forEach((value, index) => {
      if (value.length > 0) {
          let row = value.match(csvRegX);  
          if (row[0].charAt(0) === ',') {
            row.unshift("");
          }
            if(firstR){
                row.forEach((c, i) => {
                    row[i] = c.indexOf(",") === 0 ? c.substr(1) : c;
                });
                header=[...row];
                firstR=false;         
            } else{
                var obj={};
                row.forEach((c, i) => {
                    Object.assign(obj,{[header[i]]: c.indexOf(",") === 0 ? c.substr(1) : c});
                });
                ret.push(obj)
            }
        }
    });
return ret;
```


For Power Automate a custom connector is recommend (though simple HTTP request works too). What's great is you can export straight from Logic Apps to the Power Platform environment you want, with the connector being created (see [here](https://learn.microsoft.com/en-us/azure/logic-apps/call-from-power-automate-power-apps) how)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wh8sksexxjnvzd1h1j6s.png)

---

## Further thoughts

There is an elephant in the room, and that's Function Apps, as these would often be a even more powerful solution. The reason I went with Logic Apps is to keep it in the LowCode world. A Power Automate developer can transition to Logic Apps with minimum effort. Adding ProCode to a LowCodeNoCode team would add multiple challenges to the team. Though I would definitely think its a better solution if you have the right coders available.

---

**Further Reading**

- [https://learn.microsoft.com/en-us/microsoft-365/community/power-automate-vs-logic-apps](https://learn.microsoft.com/en-us/microsoft-365/community/power-automate-vs-logic-apps)
- [https://covenanttechnologypartners.com/2022/03/28/azure-logic-apps-or-power-automate](https://covenanttechnologypartners.com/2022/03/28/azure-logic-apps-or-power-automate/#:~:text=One%20difference%20between%20Azure%20Logic,to%20offer%20per%20flow%20licensing.)
- [https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-securing-a-logic-app?tabs=azure-portal](https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-securing-a-logic-app?tabs=azure-portal)
- [https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview](https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview)
- [https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-securing-a-logic-app?tabs=azure-portal](https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-securing-a-logic-app?tabs=azure-portal)