Rename OneNote Sections using Power Automate
Sep 2, 2024 • 2 • 412
Table of contents
Recently I wrote a blog regarding renaming OneNote sections based on a renamed channelname using PowerShell . In this blog same scenario is done using Power Automate.
The flow iterates iterates through all channels to determine changes.
Scenario
A new Team comes with a OneNote and every new channel gets it’s own OneNote section with the display name of the channel. When the name of the channel is modified, the name of the OneNote section isn’t updated automatically.
This blog describes how to programmatically sync the name of the channel with the name of the related section again using Powershell.
The Team contains several channels: Every channel has its own Notes tab with an associated OneNote Section.
The Team with renamed channel names, those displaynames aren’t automatically updated in the OneNote.
Create an App Registration
You can’t use the Graph API using your personal user credentials, first you need to create an App Registration. There are already plenty of blogs about creating an app registration, this won’t be covered in this blog.
Permissions needed
Notes.ReadWrite.All Channel.ReadBasic.All Group.Read.All Sites.Read.All
Unfortunately the ‘Send a Microsoft Graph HTTP request’ for Teams isn’t sufficient to use in these scenario, because the API calls that needs to be done aren’t supported in that action.
Flow actions
Initializing variables
First couple of actions in the flow are initializing variables.
OneNote ID of the Team
For the group you need to get the OneNote Id.
URI:
https://graph.microsoft.com/v1.0/groups/@{variables('groupID')}/onenote/notebooks
Method: GET
Iterate through all channels
After listing all channels of the Team, you need to iterate through all channels.
Get the tabs that are related to the current channel.
URI:
https://graph.microsoft.com/v1.0/teams/@{variables('groupID')}/channels/@{items('Apply_to_each_Channel')?['id']}/tabs?$select=displayName,configuration
Method: GET
Filter the tabs on the tab with displayName ‘Notes’ to get the tab related to a OneNote.
Set values for variables contenturl and sectionid:
Set variable contenturl:
first(body('Filter_array_Notes_tab'))?['configuration']?['contentUrl']
Set variable sectionId:
first(split(last(split(variables('contenturl'),'sectionId=')),'&'))
Get the details of the OneNote section
URI:
https://graph.microsoft.com/v1.0/groups/@{variables('groupID')}/onenote/notebooks/@{variables('notebookID')}/sections
Method: GET
Filter the section on sectionId, to be able to get the current displayname of the section.
Set variables for sectionname and channelname:
Set variable SectionName:
first(body('Filter_array_sectionId'))?['displayName']
Set variable channelName:
item()?['displayName']
Add a condition in which you compare the SectionName and channelName.
If those names aren’t the same the renaming of the OneNote section needs to take place:
URI:
https://graph.microsoft.com/v1.0/groups/@{variables('groupID')}/onenote/sections/@{variables('sectionId')}
Method: PATCH
Result
After running the flow the OneNote Section for the renamed channels are updated!
Side note
Don’t forget to add some error handling, for blogging purposes and clean screenshots it isn’t added here ☺️.