November 5, 2024

How to add Microsoft Planner checklist items dynamically using Power Automate?

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 have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

8 thoughts on “How to add Microsoft Planner checklist items dynamically using Power Automate?

    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

  1. Hi, Thx a lot for your script bit I’m having issue with the ID, I’m not able to get the TaksID out of the table.

    Cannot set child value ‘microsoft.graph.plannerChecklistItem’ on Newtonsoft.Json.Linq.JValue:'[{“id”:””,”title”: “SAM: First letter of the name + Two first letters of last name”,”isChecked”: false},{“id”:””,”title”: “Add SAM to the request”,”isChecked”: false},{“id”:””,”title”: “Create user account in the correct OU”,”isChecked”: false},{“id”:””,”title”: “Add user to the SG: O365_SyncGroup”,”isChecked”: false},{“id”:””,”title”: “Create mailbox: On-Prem”,”isChecked”: false},{“id”:””,”title”: “Move mailbox to O365″,”isChecked”: false},{“id”:””,”title”: “Add user to SG: SG Office 365 E3 Base”,”isChecked”: false},{“id”:””,”title”: “Add user to SG: SG Office 365 Teams”,”isChecked”: false}]’

    I use the concat formula you mentioned: concat(‘{“id”:”‘,items(‘For_Each_Element_in_the_Array’)?[‘TaskID’],'”,”‘,’title”: “‘,items(‘For_Each_Element_in_the_Array’)?[‘Title’],'”,”isChecked”: false}’)

    My list is build with a colomn Title and TaskID

    Can you help with this please?

    1. I had the same problem an finally figured this out.

      The problem for me was, that the result got escaped an so was not in the right json format.

      It worked for me when I added json(..) in the compose step.

      –> json(concat(‘[‘,join(variables(‘ARRAY’),’,’),’]’))

  2. I’m getting the following error. Any idea on how to fix?
    You’ll need to resolve these conflicts before importing the package
    Resource
    TEMPLATE: Add planner checklist items dynamically
    Import setup
    Create as new
    Error
    Flow save failed with code ‘DynamicOperationRequestClientFailure’ and message ‘The dynamic operation request to API ‘sharepointonline’ operation ‘GetTable’ failed with status code ‘Unauthorized’. This may indicate invalid input parameters. Error response: { “error_description”: “Exception of type ‘Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException’ was thrown.” }’.

  3. Any chance you can show how to do it from an existing Checklist on an existing planner card? For something so simple I cannot find any example of how to do it.

  4. This is a great post. One challenge I’ve had is copying checklist items from one task to another via power automate. Any insight on that one?

Leave a Reply

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

Mastodon