The solution consists of:
Working with tasks is often part of a bigger solution like an automated business process but that part is not relevant for this blog post.
There are several situations where an employee does not have enough permissions to finish a task via an email:
In the first situation, the following error message is shown by PowerApps: It looks like you don’t have access to this app. Ask its owner to share it with you. If the employee has contribute permissions for the task, (s)he could still finish the task via SharePoint of course.
For the other two situations, PowerApps needs to do error handling.
A SharePoint list contains the tasks. The available fields are customer dependent but a field containing the result and/or status is often available. Because I use an approval task as an example, the result field is a choice field containing the values "Approve" and "Decline".
The email to act on should therefor contain two "buttons", one for "Approve" and one for "Decline".
Every tasks has an unique ID being the ID given by SharePoint. This ID is used to target a specific task.
The app is a simple three screen app. The essential parts of the app are:
Param()
function.
The Param() function The Param() function is used to determine the value of a parameter added to the url when accessing the app via the web. Two parameters are needed:
Error handling Logic is added in the app for error handing:
The code for the error handling is shown below.
A connection to the SharePoint task list must be created. The list is called "Tasks" in this example.
ClearCollect(Task, LookUp(Tasks, ID = Value(Param("ID")))); If(CountRows(Task) = 1, If(IsBlank(LookUp(Task, ID = Value(Param("ID")), Result.Value)), Patch(Tasks, First(Filter(Tasks, ID = Value(Param("ID")))), {Result: {Value: Param("Result"),'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"}}); ClearCollect(TaskVerify, LookUp(Tasks, ID = Value(Param("ID")))); If(LookUp(Tasks, ID = Value(Param("ID")), Result.Value) = Param("Result"), true, Set(errorCode, 2); Navigate(Screen2, ScreenTransition.None) ), Navigate(Screen3, ScreenTransition.None) ), Set(errorCode, 1); Navigate(Screen2, ScreenTransition.None) )
First, the task list is checked if a task with the given ID exists. No result means an error situation happened like the employee has no access to the task list or no task with the given task ID is present. When an error occurs, the app navigates to Screen2.
When there is a task, it is checked if the result is empty. If not, a message is displayed on the Screen3 that the task already has been processed. If the result is empty, it is changed with the value given in the parameter "Result". Then a check is done if the task result has indeed been changed. If not, for instance when the employee has only read permissions for the task, an error occurrs and the app navigates to Screen2.
When everything goes well, the start screen is shown.
The email contains two "buttons". One for "Approve" and one for "Decline". The "buttons" are no HTML buttons but <a> elements styled with CSS so they look like buttons. No JavaScript is needed that way. The href attribute contains the url of the app followed by the parameters. For example: https://web.powerapps.com/apps/00000000-0000-0000-0000-000000000000?ID=1&Result=Approve
When a "button" is clicked, the app is launched in the web with the right parameters ("ID" and "Result").
Sending the email is part of the bigger solution, but depending on your situation/solution Flow could be an option for you. I used this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.