SharePoint Events

Create New Events in SharePoint: MS Power Automate

Premise

In this post we’ll discuss how to create a new event in the OOTB Events list in modern SharePoint Online Communication sites.

Solution

There’s no direct action card in MS Power Automate to create an event. However, we can use the standard ITEMS API to create a new list item in the Events list. While doing so, we just need to ensure that we’re updating all the required metadata values correctly.

Since, we’ll be using the SharePoint Rest API, the same approach can also be used in other custom solutions as well, to create Events. For ex., SPFx, Add-Ins, etc.

MS Power Automate

SharePoint Create Events

Code Snippet [Body]

{
    '__metadata': {
        'type': 'SP.Data.EventsListItem'
    },
    'fAllDayEvent': 'false',
    'EventDate': '@{variables(' startDate ')}', //addDays(utcNow(),2)
    'EndDate': '@{variables(' endDate ')}', //addHours(addDays(utcNow(), 2),2)
    'Title': 'Test Event from Flow: PK',
    'Category': 'Meeting',
    'Location': 'Pune, India',
    'Geolocation': {
        '__metadata': {
            'type': 'SP.FieldGeolocationValue'
        },
        'Latitude': 18.5204,
        'Longitude': 73.8567
    },
    'Description': '<b>Agenda</b><br/><br/>Test event created by <b>Piyush</b> from MS Flow' //supports rich text format
}

The solution can be divided in to the following 2 sections:

  • Flow Header
  • Flow Body

Flow Header

EntityValueUsage
Site AddressThe URL of the site.
MethodPOSTFixed
Uri/_api/web/lists/getByTitle(‘Events’)/items Fixed. Please ensure that the name of our list is ‘Events’ only. Otherwise, use your custom list name.
Content-Typeapplication/json;odata=verboseIndicates we’re sending the data in JSON format
Acceptapplication/json;odata=verboseIndicates we’re requesting to receive the data in JSON format. [Optional]

Flow Body

PropertyValueUsage
‘__metadata’‘type’: ‘SP.Data.EventsListItem’This value is usually fixed for all Events list. But it’s always better to double check its value. You can find more info regarding the same here.
fAllDayEventfalseIs all day event
EventDate2020-05-04T14:31:04.6240863ZStart date of your event. It accepts the value in ISO 8601 format. Here, I’ve just used the formula, addDays(utcNow(),2)
EndDate2020-05-04T16:31:04.9053567ZEnd date of your event. I’ve added couple of hours to the EventDate. Indicating that our event duration is of 2 hours. addHours(addDays(utcNow(), 2),2)
TitleTitle of your event
CategoryMeeting category. [Optional]
LocationPune, India[Optional]
Geolocation{
‘__metadata’: {‘type’: ‘SP.FieldGeolocationValue’},
‘Latitude’: 18.5204,
‘Longitude’: 73.8567
}
Maps co-ordinates of the meeting location. [Optional]
DescriptionMeeting agenda. It supports rich text formatting.

On running the above flow, a new event will be created as per the info provided.

SharePoint Events Web Part

Key Takeaways

  • Events list is just like any other SharePoint list.
  • We’re using the standard SharePoint REST API to create a new entry into this list.
  • All the time values provided [EventDate & EndDate] are supposed to be in ISO 8601 format only.
  • The date values should be entered equivalent to their UTC date/time only.
  • I’m using the default, Geolocation field. However, in order to create a map view, please ensure that all the prerequisites are satisfied first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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