Power Automate: Add planner checklist items dynamically

While answering questions in the Power Automate forum, I’ve seen one that pops up once in a while. How to add checklist items dynamically to Microsoft Planner? 

Add planner checklist items dynamically

For example, you have a Flow with 15 checklist items defined, and you need to add or remove some. It’s a pain to edit the Flow every time you need to do this, so here’s a template for how to do it without changing your Flow. 

However, there’s a better way so let’s explore it today.

Strategy

The strategy is simple. Keep “somewhere” the template with the checklist items you want to add to a task. This way, we can have a list in Excel or a SharePoint list containing all our checklist items. By doing this, we can quickly modify the text, add or remove them, and you don’t need to change the Flow to do it.

If you add the checklist items individually, you will see something like this:

This works for a few, but we need to generate the checklist items dynamically when you start getting many items. To do that, let’s see the structure that Flow requires. To do that, press the toggle switch:

We’ll see our items but in a JSON array.

This is the string and the structure that we need to generate. So let’s see how to do it.

The Flow

The Flow has 3 main parts.

  1. Get the checklist items from SharePoint.
  2. Build the checklist JSON array
  3. Updates the task with the checklist items

Let’s build it, but first, the global overview of what you can expect.

We’ll use the trigger “When a new task is created.” With this, you won’t need to worry about triggering the Flow. You create a task, and the checklist items are created. If you want only a subset of tasks to have checklist items, you can use the “Condition action” or the “Switch action” to filter the data.

We’re using the “Scope action” to aggregate the actions together. 

Get the checklist items from the SharePoint List.

As mentioned before, you can have any data source for this. The important part is storing the checklist items where you can edit them quickly without changing the Flow.

The SharePoint list is quite simple but does the job nicely.

The only thing I did is add a constraint so that all the IDs are unique.

These are the places where you should include any business logic to filter the checklist items you want to include. To do this, I would recommend using a Filter Query only to get the information you need. If you’re not familiar with that, please check my “SharePoint Get items” action reference and the OData reference.

Build the checklist JSON array

To build the array, we have 2 steps:

  1. Build each element for all items that we get from the SharePoint list.
  2. Combine all elements in an array.

Here’s what it looks like:

We’ll use an Apply to Each action that will check all elements from the SharePoint List. The formula is the following:

concat('{"id":"',items('For_Each_Element_in_the_Array')?['TaskID'],'","','title": "',items('For_Each_Element_in_the_Array')?['Title'],'","isChecked": false}')

It looks complex, but it’s a big concatenation of values. To do that, we’re using the “concat function.” As you can see in the formula, we’re fetching the items based on the column names in SharePoint. Also, we’re defining it as always “not checked” since adding an item already checked is not very useful, in my opinion.

To combine all, we’re using the “concat function” again and the join function.

concat('[',join(variables('ARRAY'),','),']')

You can find many more details on how the join function in my reference section, but in a nutshell, it fetches all elements in an array and combines them in a string with the separator you define. In our case, we want to use “,” to have the string that we need. So, the concatenate is adding “[“ and “]” in each side of the string. These characters indicate that we’re opening and closing an array of elements in JSON. 

In this section, we’ll do most of the work to add the checklist items dynamically. After this, we only need to add the string to the action, and we’re done.

Updates the task with the checklist items

Now that all is done, we only need to add the elements to the planning task. To do that, we can use the “Update task details” action. 

We need to provide a string with the JSON elements we previously built in the “Compose action.”

Final thoughts

The formulas may look a bit complex, but they become quite simple if you break them down in each element. All we’re trying to do is building the string that Power Automate and Microsoft Planner need to create the checklist items dynamically. As always, it’s all about strategy, so if you notice yourself constantly changing a Flow because some elements changed, think a bit deeper in how to optimize it so that you can speed up the whole process. 

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 Power Automate-related articles here.

Photo by Emma Matthews Digital Content Production on 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 →

2 thoughts on “Power Automate: Add planner checklist items dynamically

    1. Hi Moe,
      Not with Power Automate, but if you enable it on a task, all the tasks you create will show the checklist items.
      To do that, open any task, select “Show in card” (it will only show if you have checklist items). After this, all tasks that you create with checklist items will display them in the cards.
      This was the only way I managed to work, but please let us know if you find another solution.
      Cheers
      Manuel

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: