Close this search box.

How I eliminated 4,370 Viva Engage jobs with Power Automate

A few days ago, by mistake, I flooded/flooded an internal office community in Viva Engage, dedicated to informing my colleagues about the latest Microsoft Teams news. It was not intentional, I assure you! This was the result of a mistake I made when trying to optimize my Power Automate flows. In this article, I’ll explain what happened and, more importantly, how I corrected my mistake and what I learned in the process.

My mistake

It all started when I decided to create a Power Automate flow whose purpose is to reactivate all my inactive or suspended Power Automate flows once a month, because as you know after 90 days of inactivity Microsoft automatically deactivates it. So I created a flow that would go through all my flows and reactivate them if necessary. The problem is that I forgot to filter the automatic publication flow of my blog posts. This flow was supposed to publish a new blog post on the Microsoft Teams Viva Engage community, every time I publish a post on my WordPress Blog. This flow didn’t work very well and was disabled for a good reason 😅. As a result, the flow was reactivated and published several articles from my blog in a loop, without stopping!

The result

In just a few minutes, I created
4370 ads
Viva Engage ads with the same content. I didn’t notice my mistake right away, as I wasn’t consulting the community at the time. When I realized it, I was surprised! I had polluted my own community with useless duplicates and had probably annoyed all my subscribers and colleagues!

I wanted to delete all the posts I’d created, but I ran into a roadblock: there’s no way to mass delete content in Viva Engage using Microsoft’s administrative tools. At least I haven’t found any😫. I then had to delete each item manually, which would have taken hours or even days!

The solution

Fortunately, I found a solution thanks to Power Automate! Yes, the same tool that had caused my error! Back home there’s an expression for that “curing evil with evil” 😉But this time, I used it to good effect. I’ve created 2 new flows. The first uses the Viva Engage connector to list all posts in the Microsoft Teams community. Once the first flow had been executed, I was able to search for the last article I had published manually. Then, using my second flow, I used an API call to delete each item in a For Each loop.

The combination of these two flows enabled me to remove all the ads automatically generated by my error in less than two days and without any manual intervention. I was relieved to see that my community was clean again and that I hadn’t caused any irreparable damage.

1st Flow

The first step is to define a shutter release. In this case, I’ve chosen a manual shutter release. Then we define 3 variables:

  1. varAllMessages, which will unite all Viva Engage ad IDs. In fact, when we ask the Viva Engage connector to retrieve all the ads in a community, it only returns 20 🙄
  2. varNoMoreMessages, a Boolean (true/false) which returns true if there are still messages and false if there are no messages.
  3. varLastMessages, The ID of our latest ad retrieved from Viva Engage.

Then we use the Do Until operator to collect all the Viva Engage ads until there are none left:

					@equals(variables('varNoMoreMessages'), true)

Thanks to the Viva Engage connector, I’ve selected my community’s Group ID, as well as its network ID. Here it’s very important to use the Older Than option with the function below, which uses the last ID of the last request of 20 to fetch subsequent ads up to the ID of the last message 0.

					if(equals(variables('varLastMessageID'), 0), null, variables('varLastMessageID'))

Now that we’ve got all the ads, we need to stop it if we ever get to the last ad. To do this, we use a Yes/No condition. We check whether the following condition is true (is equal to $true):


If the condition is true, the Do Until loop is exited, otherwise the False branch is used, which performs the following steps:

  1. Unites the varAllMessages variable with the body of the Viva Engage connector that retrieves the ads.
  2. Adds the contents of the union to the varAllMessages variable
  3. Set the ID of the last ad retrieved in the previous step.
					union(variables('varAllMessages'), body('Get_messages_in_a_group')?['messages'])

To retrieve the last ID, we’ll need to filter our Output to retrieve only the ID, as shown below:


Finally, to count the number of total ads, we use Compose with the following input:


2nd Flow

Here are the steps of my 2nd Flow :

  1. Initialized the token bearer used to connect via API to Viva Engage.
  2. Initialize a variable that will include an array with all the Viva Engage ad IDs to be deleted.
  3. Execute an Apply to each option and delete the Viva Engage ads 1 by 1 via a DELETE API call.

The API call code looks like this:

  "type": "Http",
  "inputs": {
    "uri": "{items('Apply_to_each')}",
    "method": "DELETE",
    "headers": {
      "Accept": "application/json",
      "Authorization": "Bearer @{variables('varToken')}",
      "content-type": "application/json"

The lesson

This misadventure taught me several things. First of all, I’ve learned to be more careful with my Power Automate flows. From now on, I’ll always check conditions and filters before activating them. Ideally, I should also test my flows on a development environment before deploying them on a production environment.

Then I learned how to use the Viva Engage connector and make API calls with Power Automate. This is a very useful skill for interacting with web services and automating complex tasks. I’ll certainly be exploring the possibilities offered by this connector and by API calls.

Finally, I’ve learned to laugh at my mistakes. Instead of deleting the community and recreating it from scratch and losing all my publishing work, I decided to clean up my current community and turn it into a blog post to share my experience and learnings. By the way, I hope you enjoyed this read and got something positive out of my mistake.


Here are the Microsoft sources and articles by other people who helped me design these 2 flows:

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to migrate or connect your phone system to Teams?

Write to me and let's keep in touch!


Formulaire de contact

Discutons ensemble de vos projets


Contact form

Let's discuss your projects together