Tuesday, November 19, 2019

Adding dynamic references to default components of an Office 365 Group using SharePoint Site Designs

How nice would it be to have links visible to users to the default Planner, Calendar and Team in the quick launch of an Office 365 group from the beginning? Let me answer that for you: That would be awesome 🥳. By default, we already have in an Office 365 group links to the group’s document library, default notebook and mailbox. But what about the other components? I’ve seen many questions about this topic either during my speaker sessions about Site Designs or in Github. I've started looking for a better way to solve that problem and finally I’ve found a very elegant way to implement a solution without the need of unique identifiers. What!? No IDs?

Once again, Site Design offers the easiest way to solve this problem since by default it supports the capability of adding links to the SharePoint navigation through the addNavLink action. This action supports references to web relative links which is very helpful if you don’t know unique identifiers in advance, such as site collection URL or group ID. Therefore, I chose Site Designs as the base of this implementation. The rest of the job is done by the "_layouts/15/groupstatus.aspx?target=<target> URL. Combined to the Office 365 group URL, this URL refers to Office 365 default components such as Planner, Calendar, Team, Documents, Notebook, Members and so on. Checkout Yannick Reekmans blog post if you want detailed information about this URL and its functionality. Since addNavLink supports web relative URL, you can image how simple it is to create those dynamic links using Site Designs.

In this blog post, I will answer three questions:

How to reference to default Planner of an Office 365 group using SharePoint Site Designs?

The solution is to reference to "/_layouts/15/groupstatus.aspx?target=planner" url. This url points to the default planner of the Office 365 group. This is what the site script looks like:

{
    "verb""addNavLink",
    "url""/_layouts/15/groupstatus.aspx?target=planner",
    "displayName""Planner",
    "navComponent":"QuickLaunch",
    "isWebRelative"true
}


How to reference to default Calendar of an Office 365 group using SharePoint Site Designs?

The solution is to reference to "/_layouts/15/groupstatus.aspx?target=calendar" URL. This URL points to the default calendar of the Office 365 group. This way you don’t need to provide values such as group mail nickname or tenant name since these values are required in the default calendar URL:

https://outlook.office365.com/calendar/group/<TenantName>.onmicrosoft.com/<GroupMailNickname>

This is what the site script looks like:

{
    "verb""addNavLink",
    "url""/_layouts/15/groupstatus.aspx?target=calendar",
    "displayName""Calendar",
    "navComponent":"QuickLaunch",
    "isWebRelative"true
}


How to reference to associated Microsoft Team of an Office 365 group using SharePoint Site Designs?

The solution is to reference to "/_layouts/15/groupstatus.aspx?target=team" URL. This URL points to the associated Microsoft Team of the Office 365 group. This way you don’t need to provide values such as channel ID or tenant ID since these values are required in the team URL:

https://teams.microsoft.com/l/team/19:03d807810bd337748477d9965c215359@thread.skype/conversations?tenantId=b62a7921-3425-42b6-8a86-123eeff26f32

This is what the site script looks like:

{
    "verb""addNavLink",
    "url""/_layouts/15/groupstatus.aspx?target=team",
    "displayName""Team",
    "navComponent":"QuickLaunch",
    "isWebRelative"true
}

Note that the associated team must exist, otherwise that link won’t work properly and the end user will end up with an exception message.


Site Design and Site Script

The site script below contains all the above navigation entries. Here is what the site script looks like:

{
    "$schema""schema.json",
    "actions": [
        {
            "verb""addNavLink",
            "url""/_layouts/15/groupstatus.aspx?target=planner",
            "displayName""Planner",
            "navComponent":"QuickLaunch",
            "isWebRelative"true
        },
        {
            "verb""addNavLink",
            "url""/_layouts/15/groupstatus.aspx?target=calendar",
            "displayName""Calendar",
            "navComponent":"QuickLaunch",
            "isWebRelative"true
        },
        {
            "verb""addNavLink",
            "url""/_layouts/15/groupstatus.aspx?target=team",
            "displayName""Team",
            "navComponent":"QuickLaunch",
            "isWebRelative"true
        }        
    ],
    "bindata": { },
    "version"1
}

In order to create a Site Script based on that script, you need to run the following PowerShell command (instead of PowerShell you could also use CSOM or REST for instance). Note that the Site Script response will be stored in a variable in order to reuse it during Site Design creation:


$siteScript = Add-SPOSiteScript -Title "Dynamic References" -Content (Get-Content "C:\Temp\DynamicReferences.json" -Raw)


The next PowerShell command creates the Site Design. Here is what it looks like:

Add-SPOSiteDesign -Title "Dynamic References" -WebTemplate 64 -SiteScripts $siteScript.Id


Id                  : 12c6f045-8b61-459e-85d5-2a68224e24f7
Title               : Dynamic References
WebTemplate         : 64
SiteScriptIds       : {acab2014-71a1-48a8-b49d-442b8c276384}
Description         :
PreviewImageUrl     :
PreviewImageAltText :
IsDefault           : False
Version             : 1
DesignPackageId     : 00000000-0000-0000-0000-000000000000

Note that WebTemplate equals 64 represents Modern Team sites.


The end result

Applying the Site Design that we’ve just created, results in a left navigation that contains three new links to the default Planner plan, Calendar and associated Team. Here is what the navigation looks like:



I hope you enjoyed reading this blog postSee you on the next post! Follow me on twitter and keep up-to-date!

No comments:

Post a Comment