Flow: How to do bulk changes to an existing Flow?

Imagine that you have a flow that automates the creation of a new article for you. It creates the folders, templates, adds the tasks, etc. It has quite a lot of steps, and you want to change the initial trigger, so it’s triggered automatically instead of manually. So the only thing that changes is the initial trigger, but here we run into a problem. Microsoft flow allows you to change the trigger, but the fields from the other steps, leading to issues if you don’t validate the whole flow. So you either check all connectors to ensure all is ok or create a new flow with the new trigger and replicate all other actions. Ideally, we would like to perform bulk changes so that we can save time and ensure that all works properly.

None of these solutions are good, so here’s a nice workaround to solve this issue.

The workaround is to export the flow that we want to change, replace the trigger in the source file, and re-import it. Since we’re changing source files it can be a little bit intimidating for anyone who’s not used to read code, but follow the steps below, and you’ll be fine.

Flow Structure

At its essence, it’s just a set of JSON files. To check them for yourself, pick a Flow and extract is a package. A package contains all information that flow needs to re-create it, except the connectors that need to be configured once importing (more on this later)

This screen will give you some options to export, but you can keep the default options. Just add a name and export it.

Unzip the file, and you’ll get a folder with the following structure:

+-- manifest.json
+-- Microsoft.Flow
|   +-- flows
|       |   +-- <UUID>
|       |   |       +-- apisMap.json
|       |   |       +-- connectionsMap.json
|       |   |       +-- definition.json
|       |   +-- manifest.json

There’s a lot to explain here, but we’ll save that to another time. For now, let’s focus on the “definition.json” file. This file will contain the bulk of the flow, mainly its triggers, actions, connectors, and connections between them. Just open it in any text editor, and you’ll get a large file (length depends on the size of your flow).

The file is in the JSON mentioned above format, but we don’t need to know a lot about it to do the changes that we need. Just search for the triggers, and you’ll find something like this:

... "triggers":{
  "manual": {
    "type": "Request",
    "kind": "Button",
    "inputs": {
      "schema": {
        "type": "object",
        "required": [
          "text",
          "text_1",
          "text_2"
        ],
        "properties": {
          "text": {
            "type": "string",
            "x-ms-dynamically-added": true,
            "description": "Title of the Article",
            "title": "Title",
            "x-ms-content-hint": "TEXT"
          },
          "text_1": {
            "type": "string",
            "x-ms-dynamically-added": true,
            "description": "Section of the article",
            "title": "Section",
            "x-ms-content-hint": "TEXT"
          },
          "text_2": {
            "type": "string",
            "x-ms-dynamically-added": true,
            "description": "Main Idea for the article",
            "title": "Main Idea",
            "x-ms-content-hint": "TEXT"
          }
        }
      },
      "headersSchema": {
        "x-ms-user-name-encoded": {
          "type": "string",
          "title": "User name",
          "format": "byte"
        },
        "x-ms-user-email-encoded": {
          "type": "string",
          "title": "User email",
          "format": "byte"
        },
        "x-ms-user-timestamp": {
          "type": "string",
          "title": "Timestamp"
        }
      }
    }
  }
},...

Flow generates this file automatically, but you can read it and understand what’s happening. From the start, we find manual since the trigger is manual; the type of request is Buttonsince it was what we selected in the beginning and have multiple properties that we use as input. It’s a simplistic view to look at this file, but you can understand at least what’s happening.

Rename the unzipped folder original and let’s move to the next steps.

Generate the New Trigger

To generate the desired trigger is quite easy. Just create a new flow with a trigger that you want and export it as above. Be sure to save it to a different folder since the file with has the same name as before. Next, open the “definition.json” and search for triggers and copy that information. Be sure that you copy the whole triggers information; otherwise, it won’t work. To ensure that you’re copying the data, start counting the “{“and “}” beginning in the triggers. Each time you find a “{“add one in your head and “}”reduce one. When you reach zero stop and copy everything from the first “{“until the last”}”.

In this case, I’ll export the following:

Rename the folder to “new trigger.” It will come in handy later when you merge the changes.

Putting all together

Go to the “original” folder and open the “definition.json” file, and find the “triggers” like before. Use the same strategy as above to isolate the trigger information and replace it for the newly created one.

Save the file and generate a new zip. It’s essential to keep the zip structure the same, so be sure that you zip the contents of the folder and not the folder itself. We want a folder with the same structure above, so if you don’t get it, check if you’re zipping the folder or it’s contents.

Go to Flow, Click “Import” and upload the new zip file.

Microsoft Flow will ask you to set up the connectors.

I recommend creating a new Flow so that you can test if all is correct and keep a backup of the previous one. To do so, tap “Update” and select “Create as new”.

For the remaining connectors tap “Select during import” and pick the correct ones and press “Import”.

Test the new flow

Now test the new flow and see if this works as expected. If there was an issue during the import or running the folder, recheck the steps, so see if something is incorrect.

More than just triggers

This strategy works for any connectors. Think about a set of tasks that you’re always performing, like notifications to users or other tasks. You can implement bulk changes to your existing flows to import all these steps in one quick action.

Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and be sure to check out other tutorial-related articles here or some other Microsoft Flow articles here.

Feature Image by Jantine Doornboson Unsplash

Manuel Gomes

I'm a Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

Leave a Reply

%d bloggers like this: