Logic Apps: CSV Alphabetic sorting

Logic Apps: CSV Alphabetic sorting

Everyday we learn new things and when it comes to Logic Apps, we tend to learn even more, because it’s always shifting and new components are added. If we’re using ARM templates, the deployment brings out some challenges and with it, new things to learn (and lots of cute little things that make you want to bang your head against a brick wall).

Usually when we work with a CSV file we tend to keep the sorting according to the specification. It isn’t always alphabetical nor descending/ascending.

Sometimes, it’s just a real mess but it makes sense to the client and to the application that is consuming it.

A few days ago, whilst working on a client project and after dozens of tests, we started to see errors in our CSV file, where the headers and columns were arranged in a alphabetical sorting. This was not my intent, when I built the CSV array I wanted it to be in a certain order.

So why was this array now being sorted, who gave that command and how could I correct it?

Why and who:

As we dig in the Logic App code, we see that the Logic App is JSON in its core (my god, shocking development!). As such, it will follow JSON rules on sorting. If we set / append our variable with an array, even though that array won’t show up ordered in our code, it will when we deploy it to our Resource Group.

Lets prove this.

First, we set our LA in Visual Studio and initialize a string. Then we set two values to it ( “Append to string variable”) . One as a string and the other as an array.

{x} 
Append to string variable - pure string 
Name 
Value 
csvString 
•zulu": " 
•alpha": 
•charlie": 
romeu " 
•juliet": 
Append to string variable - array 
Name 
Value 
csvString 
•zulu": " 
•alpha": 
•charlie": 
romeu " 
•juliet":

Let’s look at the back code.

"Append_to 
string_variable -_pure_string" : 
"type": 
"AppendToStringVariabIe" , 
"inputs": 
"name": "csvString" 
"value : 
"runAfter": 
"Initialize variable": 
"Succeeded" 
"Append_to 
string_variable - 
array" : 
"type": 
"AppendToStringVariabIe" , 
"inputs": 
'name": "csvString" 
"value": 
"Zulu": " 
"alpha"• " 
"chat-lie": , 
"juliet": " 
"runAfter": 
"Succeeded" 
-_pure_string" :

Looking good so far. Our strings are set and it’s in the order we want.

Lets deploy it to our RG and check again.

Development Tools 
Logic app designer 
Logic app code view 
e 
Versions 
API connections 
Quick start guides 
Release notes 
Settings 
@ Workflow settings 
@ Access keys 
Identity 
Properties 
Locks 
Export template 
Monitoring 
Alerts 
Append to string variable - pure string 
o 
Name 
Value 
csvString 
"Zulu": 
"alpha": 
"charlie•: 
"romeu . 
"juliet": 
{x} 
Append to string variable - array 
Name 
Value 
csvString 
"alpha": 
"charlie": 
"juliet": " 
mmeu": " 
"Zulu":

Well, there it is. In ARM deployment, if we write a JSON object, on deployment it gets sorted and will appear like this in the designer tool in Portal.

Funny thing is that if we change our object to the string we want, the designer will not recognize this as a change and doesn’t let you save.

Save 
X Discard 
> Run 
Designer 
Code view Parameters Templates Connectors 
When a HTTP request is received 
Initialize variable 
Append to string variable - pure string 
• Value 
csvString 
"alpha": 
Append to string variable - array 
Value 
•alpha • : 
•juliet":

Even in Code View the changes are not recognized.

R save 
X Discard 
Run Designer 
"definition" 
"actions": 
Code view 
"*schema": "https://schema.management. 
"Append _ to string_variable - _ array 
"inputs" : 
" name" • "csvString" , 
"value : 
"Zulu": " 
"alpha" • " 
"charlie": 
"romeu" • 
"juliet"• "

But if we add other text to it, the changes are now recognized and Portal allows to save.

X Discard Run 
Designer 
"definition" 
"actions": 
Code view 
"*schema": "https://schema.management. 
"Zulu": 
"alpha" • " 
"charlie": 
"romeu" 
"juliet"• 
"Append _ to string_variable - _ arra) 
"inputs" : 
" name" • "csvString" , 
"value : 
"juliet"

But still, it won’t show you the changes and will still sort out your CSV array, once again because it’s JSON.

A few weeks ago, this behavior wasn’t noticeable I had a few Logic Apps in place with the string array in a specific order and when deploying it didn’t get sorted.

I searched in Azure updates to see if anything was mentioned but nothing came up.

How to bypass this issue?

If you’re working with a CSV file like I was, after you build your array, you’ll need to build a CSV table.

The action “Create CSV table” will take care of this from you, but as we know, it will not be in the same format we need.

{x} 
Append to array variable 
-2 
Name 
Value 
csvString 
"*Zulu": 
"Hromeu•: "2", 
"Halpha": 
"*juliet": 
"*charlie•: "5" 
{x} 
Append to array variable 
Parse JSON 
Create CSV table 
o 
From 
Body x 
Columns

(notice I’ve switched to array variable because I can’t parse the string in JSON)

So, leaving the Columns in automatic mode will mess up your integration as you can see. The output will be sorted and it won’t be what you want / need.

Create CSV table 
INPUTS 
CSV 
"Hcharlie": " 
"Hjuliet"• ' 
"Hromeu": " " 
"Hzulu": " 
"Halpha": " 
OUTPUTS 
Body 
Halphe , Hcharl ie, Hjul let , Hromeu , Hzulu 
Os 
Show raw inputs 
Show raw outputs

What a mess!! This is nothing like we wanted.

We will need to manually define the columns headers and the value they’re going to have.

Create CSV table 
• From 
• Columps 
Hromeu 
8,7'.l11et 
???? ? 
CustDT 
???? ? 
Hju11et ? 
? 
?

If you don’t have many fields, it’s quick to do this, but when you have lots of fields… well, let’s just say I hope you have plenty of time and don’t lose focus.

Create CSV table 
INPUTS 
CSV 
"Halpha": " " 
"Hcharlie": " 
"Hjuliet"• " " 
"Hromeu": ' 
"Hzulu": " 
OUTPUTS 
Body 
Hzulu, Hromeu,Ha1phe , Hjuliet, Hcherl ie 
18 
Show raw inputs 
Show raw outputs

And there we have it. Fields are now displayed correctly, the data is in the right place and we’ve managed to get around this annoying problem.

Happy coding!

The post Logic Apps: CSV Alphabetic sorting appeared first on SANDRO PEREIRA BIZTALK BLOG.

Recovering a deleted Logic App with Azure Portal

Recovering a deleted Logic App with Azure Portal

We’ve all been through it. A few days ago, I accidentally deleted a Logic App when working for a customer.

I was working on migrating from the Portal resources to a Visual Studio solution, because CI/CD is being implemented.

Luckily it was the Dev environment, but still, there was some developments that I hadn’t migrated yet! Hours of work were lost! Or then again, maybe not.

After some research I found out that there’s no way of recovering or rollback a deleted Logic App. There’s some documentation to recover an App Service but no actual mentions to LAs.

https://docs.microsoft.com/en-us/azure/app-service/app-service-undelete

Suggestions have been made in Azure Feedback, but so far, no replies.

So, how exactly do you recover a deleted Logic App?

Well, you have to dig a little bit and do some magic, but you will end up with a working Logic App after this.

Let’s work!

First, you must navigate to the Activity Log of your Resource Group.

There, you will find the last operations executed. This may not be easy, in this example I only have a few operations, but in the client tenant, I had to scavenge through a few days of logs.

ResourceGroupLA

Once you find the correct deleted workflow AKA Logic App, you open it and check the Change History. This should in preview but it will be life boat.

The “deleted resource” contains the JSON code and it is what we’re looking for. Although it requires a bit of magic dust to clean the data that’s in it, it does contain the most recent code you had. Migrating this to a new Logic App, either in Portal using Code View or in a VS solution, this is the best way to recover your little mistake.

The end result, should look like this:

And your Logic App should be ready to run!

It may not be the best way to get this nor the fastest, but it works and there’s no proper documentation for this. Hopefully, Microsoft will release a more convenient way to get your deleted code.

Hope this helps you to undo your mistakes.

The post Recovering a deleted Logic App with Azure Portal appeared first on SANDRO PEREIRA BIZTALK BLOG.

What do I need to do to start developing stateful or stateless workflows – Azure Logic Apps (Preview)? (Part III)

What do I need to do to start developing stateful or stateless workflows – Azure Logic Apps (Preview)? (Part III)

Finally, the last chapter of this blog post series where we address:

  • What we need to install to begin developing our stateful and stateless workflows using Azure Logic Apps (Preview) – PART I;
  • The first approach to what you need to create a new Logic App (Preview) resource and new stateful or stateless workflows through VS Code – PART II;

Today, I will start to explain a different and more powerful way for you to create your Logic Apps (Preview) projects and workflows. Notice that, for this approach, you need to have all the prerequisites installed; otherwise, it will not work correctly or at least certain features like Logic App Designer, debug, or inline code.

If you are like me, a developer used to work with Visual Studio as his primary tool, then you need a little learning curve to start developer using VS Code. It is a different way to developer your solutions.

Create a local project

Before you can create your logic app, the first thing you need to do is to create a local project. This will allow you to manage and deploy your logic app from Visual Studio Code.

To do that, you need to:

  • In your development environment, create an empty local folder:
    • in my case, C:VSCODEMy-First-Logic-App-Preview
    • This folder will be used for our Logic App (Preview) project that you’ll later associate in the Visual Studio Code.

Note: Using the VS Code, there are multiple ways for you to:

  • Create the local project: you can do it at the Subscription level or the Logic App (Preview) resource level (n the Logic App (Preview) extension); 
  • Create the Logic Apps (Preview) resource in Azure: Directly from the Subscription level on the Logic App (Preview) extension or during the local project deployment; 
  • And even the deployment: once again in the Logic App (Preview) resource level (n the Logic App (Preview) extension) or at the Çocal project level;

I will approach and explain the way I prefer better and which I think is the most ideal.

  • I am assuming that you have already created the Logic App (Preview) resource in Azure. If not, check to Create a new Logic App (Preview) resource in PART II.
  • In the Azure pane, from the Logic Apps (Preview) extension, expand your Subscription, select the Logic App (Preview) resource, and click on Create New Project.
  • This will open the Browse Explorer, select the folder we have created.
    • C:VSCODEMy-First-Logic-App-Preview
  • Centered at the top of the VS Code editor window, a wizard will appear asking to select a template for your project’s first workflow,  select either Stateful Workflow or Stateless Workflow. We will be using Stateful Workflow.
  • Provide a workflow name for the workflow you are creating or leave the default nameType Stateful-workflow-example and press Enter
  • Next, the wizard will ask you if we would like to open your project in a new window or the current one; select Open in current window.

Visual Studio Code reloads and will switch to the Explorer pane, showing you the workflow definition and your new Logic App (Preview) local project, which will include several automatically generated project files. For example:

  • The project will have a folder with the name that you specify for your workflow – Stateful-workflow-example. Inside this folder, the workflow.json file contains your logic app workflow’s underlying JSON definition.
  • Also host.json and local.settings.json files;
  • and so on.

Developing your Logic Apps in VS Code

Now that we have everything we need already created, we can start developing our logic apps locally on VS Code.

To do that, you need to:

  • Expand the project folder, in my case MY-FIRST-LOGIC-APP-PREVIEW, and then expand your workflow folder, Stateful-workflow-example. Righ-click workflow.json file and select Open in Designer.
  • From the Enable connectors in Azure list, select Use connectors from Azure, which applies to all managed connectors that are available and deployed in Azure, not just connectors for Azure services.
  • From the Select subscription list, select your subscription. This will be were the connectores will be created.
  • And finally, from the Select a resource group for new resources list, select the resource that you created for this project.
  • After that, the Logic App Designer appears, the Choose an operation prompt appears on the designer and is selected by default, which shows the Add a trigger pane.

Note: If you have .NET Core SDK 5.x, this version might prevent you from opening the logic app’s underlying workflow definition in the designer. Rather than uninstall this version, in your project’s root location, create a global.json file that references the .NET Core runtime 3.x version that you have that’s later than 3.1.201, for example:

{
   "sdk": {
      "version": "3.1.101",
      "rollForward": "disable"
   }
}
  • Make sure that you explicitly add that global.json file to your project at the root location from inside Visual Studio Code. Otherwise, the designer won’t open.
  • To check the versions that are installed on your computer, run the following command:
..Users{yourUserName}dotnet --list-sdks

And the rest is basically the same that we are already used to doing it in our “original” Logic Apps, or using the Azure Portal or inside Visual Studio. We need to add a trigger and actions.

  • On the designer, select the Choose an operation an in the Add a trigger pane, under the Choose an operation search box, make sure that Built-in is selected so that you can select a trigger that runs natively.
  • In the Choose an operation search box, enter when a http request, and select the built-in Request trigger that’s named When a HTTP request is received.
  • When the trigger appears on the designer, the trigger’s details pane opens to show the trigger’s properties, settings, and other actions.
    • This means that you can now define the JSON Schema, method, and all the other properties of this trigger.
    • Let’s leave the default for now.
  • Because this is a simple sample, let’s add an HTTP Response to our logic. On the designer, under the trigger that you added, select New step.
  • On the Add an action pane, under the Choose an operation search box, enter Response, and select the built-in Request action that’s named Response.
  • To have a more friendly response, set the body property of the Response action to be:
{
     "Message": "Welcome to your first Stateful Workflow"
}
  • Finally, on the designer, select Save.

Now what we need before deploying this is to run and test this workflow locally.

Testing locally our Logic Apps

To do that, we need to:

  • On the Visual Studio Code toolbar, open the Run menu, and select Start Debugging (F5).
    • A Terminal window will open so that we can review the debugging session.
  • Because this workflow is trigger by an HTTP request, we need to find the callback URL for the endpoint on the Request trigger. Usually, we go to the When a HTTP request is received trigger, after we save our Logic App, and on the HTTP POST URL, we would find the callback URL. However, we will not find it locally. Instead, we will find a message saying, “Url not available during authoring in local project. Check the Overview page.”
  • As the message describes, for us to now the callback URL for the endpoint on the Request trigger we need to:
    • Reopen the Explorer pane so that you can view your project.
    • And from the workflow.json file’s inside the workflow folder – Stateful-workflow-example – right-click and select Overview.
  • There you will find the Workflow Properties like the Callback URL but also the local Run History of that workflow
  • Copy that URL to Postman or any other tool, and test sending a request to see if you get the desired outcome.

On the Overview page, you will get another entry on the Run History.

How can I add more workflows to my project?

Can I add more workflows to my local project? If so, how can I do it?

Yes, you can. And to do that, you need to:

  • Switch back to Azure pane and under Logic App (Preview), select your Logic App resource, and select Create Workflow.
  • A wizard will appear asking to select a template for your workflow,  select either Stateful Workflow or Stateless Workflow. We will be using Stateful Workflow.
  • Provide a workflow name for the workflow you are creating or leave the default name, Type Another-Stateful-workflow-example, and press Enter.
  • Now, if we switch back again to the Explorer pane, we will notice that we have another workflow added to our local project.

Publish (deploy) to Azure Logic App (Preview) resource

Everything we created above is not created/publish on Azure, they were developed and created locally. Nevertheless, from Visual Studio Code, you can deploy your project and with it all your workflows directly to Azure. If the Logic App (Preview) resource type is not yet created, you can create in Azure during the deployment.

To do that, you need to:

  • On the Visual Studio Code toolbar, select the Azure icon.
  • On the Azure: Logic Apps (Preview) pane toolbar, select your Logic App (Preview) resource type, in our case, My-First-Logic-App-Preview, and then select Deploy to Logic App.
  • The deploy wizard will appear asking to Select subscription from the list.
  • And then to Select Logic App (Preview) in Azure. We will be selecting the one that we craete previously
  • If a message appear asking you if you want to continue with the deployment and overwrite any previou depoyment, select Deploy.

This will trigger the deployment process to Azure. Once the deployment is finished, you will be able to see your stateful workflows live in Azure and enabled by default.

The post What do I need to do to start developing stateful or stateless workflows – Azure Logic Apps (Preview)? (Part III) appeared first on SANDRO PEREIRA BIZTALK BLOG.

What do I need to do to start developing Logic Apps from Visual Studio?

What do I need to do to start developing Logic Apps from Visual Studio?

Azure Logic Apps Tools is available for Visual Studio 2019, 2017, and 2015 Community edition or greater and will allow you to design and deploy your logic apps from within Visual Studio. The Logic App designer integrates with the current Azure Resource Group project so you can seamlessly work with resource deployments that include Logic Apps.

Although this tool is officially supporting three versions of Visual Studio, I will advise you to install it only on Visual Studio 2019 and not in older versions. At some point, they will be officially removed or discontinued.

Prerequisites

  • Visual Studio 2019, 2017, or 2015 – Community edition or greater;
  • Visual Studio Tools for Azure: Azure SDK, tools, and projects for developing cloud apps and creating resources using .NET Core and .NET. Important also to create hybrid solutions without having the need for another development environment.
    • In the Visual Studio installer, install Visual Studio (or modify an existing installation). Make sure the Azure development and ASP.NET and web development workloads are selected.
  • and run the following command:  Install-Module -Name Az

Note: of course, for this or any other approach describe above, you need an Azure subscription or sign up for a free Azure account.

Install Azure Logic Apps Tools for Visual Studio 2019

AftAfter you install the prerequisites, this is a straightforward process. To accomplish that, we need to:

  • Open your Visual Studio, on the entry screen select the option Continue without code ->
  • Then on the menu, navigate to Extensions > Manage Extensions
  • Select Online and search for Logic Apps
  • The add-in will be listed in the search results section. Click Download to download and install the add-in. You need to close your Visual Studio in order to begin installing this extension. 
  • On the VSIX Installer screen
    • Make sure that the correct version of Visual Studio is selected.
    • Click Install or Modify. This will download and install the add-in to your version of Visual Studio.
  • At the end select Close.

Creating a Visual Studio Logic App project

The Logic Apps designer integrates with the current Azure Resource Group project. That saying, you will not find any Logic App template from the list of templates. Instead, we need to create an Azure Resource Group project to get started and to do that, we need:

  • Open Visual Studio and on the Create a new project panel, select C# -> Azure -> Cloud, or select for Azure Resource Group;
    • Select Azure Resource Group from the template list;
  • On the Configure your new project panel, give a proper Project name, Location, Solution name, and leave the Framework as .Net Framework 4.7.2 and select Create.
  • Finally, on the Select Azure Template panel, from the Visual Studio Templates list, select the Logic App template and select OK.

This will create an empty Visual Studio Logic App solution. Now on the Visual Studio solution:

  • Right-click on the LogicApp.json file and select Open With Logic App Designer
  • This will open a Logic App Properties window, where you need to:
    • Define the credentials to authenticate on the Azure subscription;
    • Define the Subscription and Resource Group where you want to create these resources;
    • Define if you want the Location to be in the same Region or in an Integration Service Environment (ISE);
  • And then select OK.

This will embed the Logic App designer inside the Visual Studio.

Now you need to select a common trigger, a template, or use a blank Logic App to start creating your business process.

The post What do I need to do to start developing Logic Apps from Visual Studio? appeared first on SANDRO PEREIRA BIZTALK BLOG.