cancel
Showing results for 
Search instead for 
Did you mean: 
aprildunnam

Get SharePoint Calendar Events and Post to Teams

Hello Flow Fans!

 

Today I wanted to write about a solution I recently wrote which ties together Flow, SharePoint and Teams.  I wanted to utilize a recurring Flow, set to run every day to grab the current days events from a SharePoint calendar and post a message to my Teams channel to let everyone know what events are occuring today.  Pretty cool right?  Let's take a look at how to set this up.

 

1.  Create a blank Flow and add a Recurrance Trigger.  Configure the advanced settings so that the Flow runs every day at 8 per the screenshot below:

Screen Shot 2018-09-10 at 9.36.13 AM.png

 

 

2.  Add a Get Items - SharePoint Action.  Point this to the URL where you SharePoint calendar is stored. 

Note:  SharePoint Calendars will NOT show in the dropdown of list options.  You have to click the "Manual" option and type in the name of your SharePoint Calendar

 

3.  Now we need to configure the Filter options for the Get Items so that it will get only the current day's items.  This step is a little tricky. We can't do a simple EventDate eq 'utcNow()' because the EventDate is a Date Time so that evaluation will only work if the exact date and time matches.  Additionally, we can't use a formateDate on the EventDate field either.  That leaves us with using greater than and less than expressions to check if the event is between the 12am and 11:59pm on the current date as shown below:

 

EventDate ge 'utcNow('yyyy-MM-ddT00:00:00Z')' and EventDate lt 'addDays(utcNow(),1,'yyyy-MM-ddT00:00:00Z')' 

 

Screen Shot 2018-09-10 at 9.37.13 AM.png

 

4.  We need to get these results in a user-friendly format to post to Teams.  To do this, we will insert a "Data Operations - Select" action.  Pass in the Values from our Get Items action and fill out the item value pairs for whatever information you want to show as shown in the screenshot below:

Screen Shot 2018-09-10 at 9.47.42 AM.png

 

 

5.  Next, we'll insert a "Data Operations - HTML" action so that we can format our output into an easy to read HTML table layout

Screen Shot 2018-09-10 at 9.47.46 AM.png

 

 

 

 

6.  Finally, add a Teams - Post to Channel action.  Point this to your Team and Channel and set the value to your HTML Output

Screen Shot 2018-09-10 at 9.47.47 AM.png

 

 

 

You can use this same method to send a daily email of the current day's events as well.  Hope this was helpful!

Comments

Great stuff!

I am doing this today.

But how would you modify your formula if you wanted the flow to only run once per week and include the whole weeks events in the post on teams?

 

So for example UtcNow +5 days for example.

Flow is triggered every monday at 8 in the morning.

Export all events from monday (the day the flow runs) and then 5 days ahead.

 

That should be pretty easy to do.  If you set the Flow to run once a week at the start of the week then the only thing you'd need to change in the directions is the Recurrance settings and the filter in the Get items.  If you change the "Less Than" function to this:  

 

addDays(utcNow(),5,'yyyy-MM-ddT00:00:00Z')

That should be the events from the start of the week plus 5 (typical work week).

 

Well i got it to work in a way.

 

First error however is that the table that is created mixes the events. So i get one event that is today in the middle of the list and one event that is in two days at the top of the list.

Screenshot: http://prntscr.com/ku3v1j

 

Second error i found is that the times in the post is all wrong.

If you view the screenshot above and see the first start time in the top of the list.

It says 12.30.00

But in the calendar that event is scheduled for 14,30.00

So it seems everything is off by two hous

 

 

Nice job, another alternative would be to use a rich card to post to Teams, which can then be more interactive. 

 

https://medium.com/@smcollier/using-flow-to-post-todays-events-from-sharepoint-to-teams-964f5fd2407c...

Anonymous

@aprildunnam  - How can you make the Flow check if there are or aren't items. If there aren't for the day, don't send.

@Anonymous  - The easiest way is probably to add a Compose Action in right after your SharePoint Get Items action.  Put in an expression in the Compose Action to check for the length of the Get Items call.  Then you can add in a Condition to only continue if the length is not zero.  The formula for checking the length would be like this:

 

length(body('Get_items')?['value'])
Anonymous

@aprildunnam I'm using this exact flow for everyone's birthday and it works great except I'm experiencing a couple issues.  It will post someone's birthday the day before the actual event.  For example, if my birthday is tomorrow, it will post today.  I tried changing the 1 to 2 in the addDays piece, but that resulted in posting past and future birthdays instead of just 'today.'  Do you think 0 would work?

 

I'm also trying out the compose/condition steps as I type this and I just want to make sure I'm configuring this right.  I added Compose after SharePoint - Get items; then added Condition where it says "Output (from Compose action) - is greater than - 0."  Then I moved everything following (Select, Create HTML table, Post a message) under the "If yes" side.  Leaving the "If no" side blank should essentially do nothing, correct?

@aprildunnam - Hi April, I just discovered Flow & am taking my first few baby steps on LinkedIn Learning. Will you please provide guidance on 2 items for me related to your post?

  • Is there a way to add cell padding to the HTML table? This would help visually.
  • Is there a way to format Start Time & End Time to show only the date instead of date/time? Link to instructions is perfectly fine.

Thank you!

@randallroach - That's correct, in that condition if you have nothing on the "no" side then no action will take place.  Regarding getting the incorrect dates, are you also pulling the data for the birthdays from a SharePoint list or a different location?  Sounds like it could be a date/time issue.

@randallroach  - You can remove the time from the date/time by using this expression:

 

@formatDateTime(utcnow(),'yyyy-MM-dd')

Just replace the "Utcnow()" with the name of your field

 

You're limited to how you can format the HTML table.  To make it look a little better, you can replace your Post to Teams with the following expression to add a border around the table:

 

replace(body('Create_HTML_table'),'<table>','<table border="1">') 

 

I haven't tried it but might be able to add in cell padding.  I'll have to test that to see if it works. 

Thanks @aprildunnam, I'm very close. Will you please tell me the correct location to place the expression?

@formatDateTime(utcnow(),'yyyy-MM-dd')

I tried to put it in the Select action to replace the "Start Time" field, but I got an invalid error. I used the code

@formatDateTime(EventDate,'yyyy-MM-dd')

Will you please let me know if I'm placing the code in the right spot & if the code itself is correct? Thanks!

@aprildunnam, here's a screenshot for context

select action.png

If you hover over the End Time property you have in your mapping you should see a tooltip pop up that shows a value.  It's probably something like item()['EventDate'].  That's what you'll want to use in the formatDateTime

@aprildunnam, worked beautifully, thank you for the remedial help 🙂

@aprildunnam hi April, my flow is working great for single day events, but it's (by design) not showing events that span multiple days (e.g. recurring series or multi-day event). is there a way to adjust step 3 so that the flow pulls any appointment that starts on the current day, regardless of when the end date is? thanks!

@randallroach Did you ever figure this out? Looking to capture multi-day events as well in my Flow.

This solution does not work for recurring events. Has anyone tackled this? I'm seeing that the important recurrence data is not returned in the Get Items JSON.

Anonymous

I had this working perfectly for last year, but I ran into an issue with recurring events on SharePoint.  It's almost like my flow isn't seeing any events this year, because they were created as recurring.  Is there an easy fix or would I need to recreate every birthday??

Hi @aprildunnam, I'm having the same issue of the post above. How can you get the recurrence events that are happening in Today? 

 

Found a way to get all the recurrecences :

EventDate le 'EXPRESSION FOR START DATE' and EndDate ge 'EXPRESSION FOR END DATE'

EXPRESSION FOR START DATE: formatDateTime(utcNow(),'yyyy-MM-ddT00:00:00Z')
EXPRESSION FOR END DATE: formatDateTime(utcNow(),'yyyy-MM-ddT23:59:00Z')

 

But if at the the recurrence is too long also will be listed but that doesn't mean that is happening or ocurring today.  

More than appreciated any help

Hello @aprildunnam , has anybody figured out how to make the Flow post events that are recurring?  Like what is said in prior posts, the Flow works great for events assigned in the current year but fails in year 2 and beyond. 

 

I tried what 'criojsab' did in the post above this one and the Flow picked up every event for the entire year and posted it to my Teams Channel.  I had to stop the Flow after it posted over 40 events in 5 minutes.  I tried changing "End Date" to "Event Date" and this change didn't work either.

 

I know this is an old post, so I hope someone sees this and will have a resolution.  I can't seem to find anything regarding this issue on the internet.

About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/