I am an avid SharePoint enthusiast who works as an Independent SharePoint Consultant based in Leeds, United Kingdom.
I am one of the organisers of the Yorkshire SharePoint User Group in the United Kingdom.
I have been designing and building SharePoint solutions since 2006.
In this blog post, I wanted to highlight some of the fun and games that I had working with Microsoft Planner App-Powered tasks.
I have seen the following issues. In this blog post, I highlight some of the problems that I have. I am sure that some of the issues, which are bugs, will get fixed as we get closer to GA:
If you complete a task, it requires a refresh of the plan for the user interface to pick up the change and show the task as completed.
Accessing completed tasks from the Teams Activity feed can bypass the App Powered Tasks.
When you delete the Teams App, it will disable the Task Powered App interface, which, to be honest, all makes sense.
Creating the various staging URLs and deep link URLs is tricky. Please use my examples to help you get it right.
Do not use a # symbol in your external IDs, as they cause issues with the encoding and decoding of URLs. In particular,r they break the link for Teams stage links. The outcome is that the staging dialog does not appear, and you are taken into the web instance of Microsoft Teams.
When developing a solution, use a Dev and environment-specific plan because your tasks are going to point to your development/environment Teams app.
The Planner task may miss the start button and app task-powered element if a user is on the planner and immediately opens the task.
These issues seem to have been fixed:
The app-powered task user interface does not always show.
Immediately created tasks often miss the buttons and app-powered task features.
Accessing tasks from Teams Activity can sometimes bypass the App Powered Tasks.
I am sure these issues will get resolved as the solution gets closer to release. My original development issues are getting fixed, which is great news. However, I wanted to highlight the things that I am seeing, and I will feed them back to Microsoft.
Conclusion
This post highlighted some issues that I have seen with Planner App Powered tasks. However, I can already see that some of these issues that I originally flagged have been resolved. This is great news, and I hope is a sign that the solution is coming towards being ready for general availability π
In the first blog post, I provided an example of what they are and why you want to use them. π If you have not read the first post, I invite you to start from there.
In the previous post, we introduced App-Powered Tasks and why you want to use them.
In this post, we will discuss the architecture and process of building an App-Powered Task solution for Microsoft Planner.
An example architecture of an App Powered Task solution looks like the following
The ingredients for the solution are
A Microsoft Entra ID Application will be used to create the business scenario plan and manipulate the business scenario planner tasks.
An API to create, get, update and complete the planner tasks. I am also using this to create the business scenario plan.
A Microsoft Teams App that will be used to action the task. In my example, I am using a SPFx teams app to achieve this.
A Planner Plan
A Team within Microsoft Teams that hosts the Planner Plan.
Record the object Id, which is also the Group ID, we will need that again shortly.
Now that we have the Entra ID application and Microsoft 365 Group, next you’ll need the code.
Getting the code
The code can be found in my GitHub repository, there are two parts to the code, which will go into a bit more detail shortly. We have the API which is an Azure Function and the user interface which is a Teams Toolkit created SharePoint Framework webpart. The web part will display the custom task interface for the user.
Clone the GitHub repository to local your machine.
Get the code running
In this blog post, we are going to run everything locally, so that you can get the code working, debug it, and tweak it so it works for you.
First, open the Azure Function Project in Visual Studio 2022.
Second, open the Read Receipt SharePoint Framework webpart in Visual Studio Code.
Read Receipt Azure Function Setup
To setup and get the Azure Function working you will need to configure the Azure Function with the following settings so that it can use the Entra ID application that you setup and Microsoft Team.
Open the local.settings.json file and update the file with the following settings:
ClientId uses the Client Id for the Microsoft Entra ID application you created.
ClientSecret uses the Client Secret that you created previously.
TenantId use the directory Tenant Id that is found in the Azure Portal, Entra ID Application as shown below.
Next, configure the Group ID using the value you got from the Microsoft Team.
BusinessScenarioName – the name of the Business Scenario
PlannerName – the name of the Planner Plan
SharePointHostName – the prefix of your SharePoint Online URL. e.g acme from acme.sharepoint.com
TeamsTaskAppId – the Application ID for your Teams App
InDeveloperMode – set to true
TestUserPrincipalName – provide your username/email address here for your test user.
In the Repository is a folder called Postman, which contains the Postman Collection that we will use to run the Azure Function functions to set up the Business Scenario Microsoft Planner Plan.
Once you have downloaded and installed Postman grab the Postman collection that I have created for you. This is found in GitHub, in the Postman folder.
Run the Read Receipt Azure Function To Setup Planner Plan
From Visual Studio 2022.
Find the Timer Function called CreateConnectSyncPlanFunction.
Put a breakpoint if you want to follow the code.
Press F5 to run and debug the Azure Function on your computer.
This will create a plan using the configuration settings you specified in the local.settings.json
All being well the plan has been created in your Microsoft Team.
Please check that it was created ok by going into Planner and looking for the Plan with the name you provided.
Setup the Read Receipt Microsoft Teams App
Now that we have the Plan created, we need to get the user interface setup within Microsoft Teams.
The configuration of the Teams App is using the various env.local, env.dev and env.prod files to manage the app IDs etc. I have left the local and Dev IDs as to the ones that I have been using.
Hopefully, that will be ok, and it will make life a bit easier for you to get the solution up and running.
In order to use these just change the .env.local.txt to .env.local and .env.dev.txt to env.dev. I have removed the tenant Id as you don’t need that and it will get in the way.
The API needs to know these IDs so that when the tasks are created then the right link is provided to the user to take them into our custom user interface.
Use Teams Toolkit to get up and running by doing the following:
From VS Code’s Terminal use npm -i to install all the dependencies.
Rename the /env/env.local.txt to /env/env.local
Rename the /env/env.dev.txt to /env/env.dev
Start local provision of the Teams App by
From Teams Toolkit Plugin
Choose to start the local environment with Teams Workbench (local).
If you have not logged in before you’ll be asked to login into your Microsoft 365.
After a few minutes of compiling, you should have a browser fire up, asking you to open the Teams App.
Now you have the Teams App running we are ready to create a task.
Before that let me just talk about deep linking and Microsoft Teams.
A word about Teams Deep Links
I will talk about the problems that I had with Microsoft Teams Deep Links in the next post but let’s go over what we need to set up for the links to work.
The official documentation on deep link URLs within Microsoft Teams is available on learn.microsoft.com.
However, we need to use a stage link which looks like this:
appId – this is the ID for the Teams App that should be opened by the link.
entityId – this is the ID for the tab that should be opened by the link.
contentUrl – this is the URL that should be used to render the content and will explain further next.
name – the name of the dialog to open.
openMode – how should the link be opened; I am using a dialog modal to keep the user in the context of Planner.
The contentUrl is one of the more important of the parameters and its value is the key to getting the contents of the dialog to render properly. Here is the example from the code:
We have two in the code base, one for when we are developing and the other when the application is being used normally.
Development link
var teamsAppDevelopmentLinkUrl = $"https://[yourtenantname].sharepoint.com/_layouts/15/TeamsWorkBench.aspx?componentId=fac21461-7439-49d1-a2ce-f5ab67b67a91&subEntityId={teamsAppExternalObjectId}&teams&personal&forceLocale=en-gb&loadSPFX=true&debugManifestsFile=https://localhost:4321/temp/manifests.js";
Notice the link which has your SharePoint prefix for example https://acme.sharepoint.com but directs the user to TeamsWorkBench.aspx. This allows you to debug the code. It took me a while to work out this was the URL to use and I took it from the Teams Toolkit configuration file.
Additionally, it has the componentId and subEntityId properties.
componentId – this is the tab that should be opened by the link.
subEntityId – I have added this because I want to ensure that I know which task to open. This is the external object ID that is created and associated with the business scenario task.
Now for the normal, non-development link
var teamsAppLinkUrl = $"https://[yourtenantname].sharepoint.com/_layouts/15/teamshostedapp.aspx?componentId=fac21461-7439-49d1-a2ce-f5ab67b67a91&subEntityId={teamsAppExternalObjectId}&teams&personal&forceLocale=en-gb&loadSPFX=true";
This is similar to the development version of the link, except that we do not have the TeamsWorkbench.aspx mentioned but rather the teamshostapp.aspx instead. The properties are still the same, componentId and subEntityId as mentioned above.
Now that you understand the different links then we can bring it all together to create the encoded Context Object with the following code.
var teamsAppDevelopmentLinkUrl = $"https://ithinksharepointltd.sharepoint.com/_layouts/15/TeamsWorkBench.aspx?componentId=fac21461-7439-49d1-a2ce-f5ab67b67a91&subEntityId={teamsAppExternalObjectId}&teams&personal&forceLocale=en-gb&loadSPFX=true&debugManifestsFile=https://localhost:4321/temp/manifests.js";
var teamsAppLinkUrl = $"https://ithinksharepointltd.sharepoint.com/_layouts/15/teamshostedapp.aspx?componentId=fac21461-7439-49d1-a2ce-f5ab67b67a91&subEntityId={teamsAppExternalObjectId}&teams&personal&forceLocale=en-gb&loadSPFX=true";
if (inDevelopmentMode)
{
teamsAppLinkUrl = teamsAppDevelopmentLinkUrl;
}
var contextObject = $"{{\"appId\":\"{teamsAppId}\",\"entityId\":\"{teamsTabEntityId}\",\"contentUrl\":\"{teamsAppLinkUrl}\",\"name\":\"{teamsAppTaskTitle}\",\"openMode\":\"modal\"}}";
var encodedContextObject = System.Uri.EscapeDataString(contextObject);
// the teams link must use a stage link https://learn.microsoft.com/en-gb/microsoftteams/app-powered-tasks-in-planner#example
var teamsAppTaskLink = $"https://teams.microsoft.com/l/stage/{teamsAppId}/0?context={encodedContextObject}";
var encodedTeamsAppTaskLink = Encode(teamsAppTaskLink);
Finally, we have an Encode function which comes from the Microsoft documentation but removes certain key characters from the link to ensure that when it is created as part of the Business Scenario Task with the Microsoft Graph SDK it is valid.
Using the URL to Create Your First Business Scenario Task.
We just need to make some tweaks to the code in our API to make sure it’s sending you to the right place.
To be honest, getting the URL right was one of the hardest parts of getting the solution going! π
However, provided you have setup the local.settings.json correctly with the SharePoint Host Name and Teams App Id, everything should get setup correctly.
Now you understand the structure of the URL, do the following to create your first business scenario task.
Open Postman
Find the CreateBusinessScenarioTask request in the Postman Collection
Click on the Body tab and update the properties to use values which make sense for your environment.
Here is an example from my environment.
The following parameters are required:
externalId – The externalId is the unique identifier that is used to find the task. Please be aware that the externalId needs to be unique in your plan.
userPrincipalName – the user principal name of your test user. bob@domain.com.
contentTitle – the title of the content that needs to be read.
contentUrl – the URL to the content that needs to be read.
Click on Send and your Azure Function should be fired and a task returned in the response from Postman.
Additionally, now, you have a Microsoft Planner Plan with an App-Powered Task created. If you browse to the Microsoft Planner Plan using https://planner.cloud.microsoft you’ll see the task in the My Tasks view.
The highlighted part of the screenshot above, is an indicator that the task is an app-powered task.
Try out the task, open it and click “Start task” and see if works, make sure you still have the VS Code debugger running.
All being well you will see the task open up in your debug browser.
Congratulations you have created your first App Powered Task App!
I wanted to give you a bit more information on the deep link URLs as this took me a while to get going and so wanted to share my findings.
How do we use these deep links?
The links are created and associated with a Business Scenario Task through the References property. The links are a bit odd to set up for the first time but after you have done one you will soon get used to the pattern as the Graph SDK and Planner Api uses a similar pattern in several areas. The pattern provides the API with a lot of flexibility and extension points for future Planner features.
Well the code here does the work. Notice line 6 and 7 which create the container for these PlannerExternalReferences the PlannerExternalReference is created and setup the .Type is important as this is used by Planner to note whether the task is App-Powered. The PlannerExternalReference is added using the encoded Teams link plus the PlannerExternalReference object which is added to the AdditionalData property.
// the teams link must use a stage link https://learn.microsoft.com/en-gb/microsoftteams/app-powered-tasks-in-planner#example
var teamsAppTaskLink = $"https://teams.microsoft.com/l/stage/{teamsAppId}/0?context={encodedContextObject}";
var encodedTeamsAppTaskLink = Encode(teamsAppTaskLink);
// setup the external references used by the teams powered app task.
var plannerExternalReferences = new PlannerExternalReferences();
var plannerExternalReference = new PlannerExternalReference();
plannerExternalReference.Alias = teamsAppTaskTitle;
plannerExternalReference.Type = "TeamsHostedApp";
plannerExternalReference.PreviewPriority = " !";
plannerExternalReferences.AdditionalData.Add(encodedTeamsAppTaskLink, plannerExternalReference);
// create a task
var businessScenarioTask = new BusinessScenarioTask()
{
Title = teamsAppTaskTitle,
PercentComplete = 0,
StartDateTime = DateTime.Now,
DueDateTime = DateTime.Now.AddDays(1),
Target = new BusinessScenarioGroupTarget()
{
GroupId = groupId,
TaskTargetKind = PlannerTaskTargetKind.Group
},
BusinessScenarioProperties = new BusinessScenarioProperties
{
ExternalObjectId = teamsAppExternalObjectId,
ExternalBucketId = watchBucketName,
},
Details = new PlannerTaskDetails
{
Description = $"Please read the content, {readReceiptTaskResponse.ContentTitle} and confirm that you have read the content",
References = plannerExternalReferences
},
Assignments = taskAssignments
};
await graphClient.Solutions.BusinessScenarios[theBusinessScenario.Id].Planner.Tasks.PostAsync(businessScenarioTask);
We create the business scenario task (please note I have stripped out the other code to assign the task etc to help readability.
Finally, we add the task to the Business Scenario plan using the PostAsync function.
Conclusion
I hope that you found this article useful and got the code up and running. Please reach out and raise any issues within the GitHub Repository and I will look and get back to you or add any fixes that you might discover.
In this blog post we introduced App Powered Tasks with Planner and using a SharePoint Framework Teams App and Azure Function we were able to create a Business Scenario Plan, and tasks and set up a task to open up a Teams App that will allow you to put a custom user interface around the Business Scenario Task.