Sometimes we might be completing tasks in a Power App that’ll notify users in some way. But what if those users are away and we need to send the information to someone else? In Power Apps, we can retrieve a users’ out of office message so we can make real-time decisions.
This is something I’ve done a few times over the years and, having done so again recently, thought it would be a good tip to share.
Table of Contents
ToggleOut of office on
My account has an active out of office / automatic reply / away message / whatever you want to call it:
I’ll use this to show the 2 methods we can use in Power Fx to retrieve the out of office text.
Data source
In the Power App designer, select Data. Search for then add the Office 365 Outlook connector:
To retrieve a users’ out of office, we’ll be using the GetMailTips actions. Whilst it’s preferable to work with the latest API version (ie V2), there are some quirks/differences between the MailTips ones. I’ll cover both methods in this article.
GetMailTips method
If I wanted to retrieve my, or anyone else’s out of office message, I can add a label and use the following Power Fx in the Text property. I can state any email address here, so long as it’s on the same domain as the account I’m using to build the app:
Office365Outlook.GetMailTips(
"craig.white@platformsofpower.com").AutomaticReplies.Message
However, the out of office will likely be in HTML format, meaning that the code above will show some references to <div> and <br>:
To get around this, you can wrap the Power Fx in the Plain Text function.
PlainText(Office365Outlook.GetMailTips(
"craig.white@platformsofpower.com").AutomaticReplies.Message)
The output isn’t terribly smooth though. For example, line breaks seem to be doubled and so the formatting isn’t perfect:
Alternatively, you can use a HTML text control to visualise the output. Configure the HtmlText property with the Power Fx without using the Plain Text function:
GetMailTipsV2 method
There are two key differences with this approach:
1- The Power Fx syntax is different.
2- You can’t reference the output in a non-behavioural way.
You’ll need the following to retrieve the out of office message for the email address of your choice:
Office365Outlook.GetMailTipsV2("automaticReplies",["craig.white@platformsofpower.com"]).value
However, you can’t simply reference this in a label control. The V2 action can only be called using a behavioural function – such as OnVisible, OnStart or OnSelect:
Adding a button to the app, I can configure the OnSelect property to retrieve an object and store as a variable or collection instead:
Set(
gvUsersOutOfOfficeV2,
Office365Outlook.GetMailTipsV2(
"automaticReplies",
["craig.white@platformsofpower.com"]
).value
)
We can then drill into the variable to get the desired property, by adding this to the text property of a label:
First(gvUsersOutOfOfficeV2).automaticReplies.message
Alternatively, you can string all the Power Fx together as one block, then reference the variable directly. This would all still have to run from a behavioural property though:
Set(
gvUsersOutOfOfficeV2,
First(
Office365Outlook.GetMailTipsV2(
"automaticReplies",
["craig.white@platformsofpower.com"]
).value
).automaticReplies.message
)
You may still need to visualise the output, either by adding the variable to a label (with the Plain Text function) or a HTML Text control (without Plain Text):
Scenario
I am using Power Apps to determine who an approval needs to go to. For each approval step in the process, the business has nominated 2 approvers; a primary and secondary. The approval must always go to the primary approver unless they’re on leave, in which case it must go to the secondary. Ideally we need to see this information real-time.
A list of process approvers are stored in a table and kept up to date regularly. For the purposes of this example, we’ll replicate the first approval step by building the following collection:
// Store list of approval steps & approvers
ClearCollect(
colApprovers,
{
ApprovalStep: 1,
ApprovalOrder: 1,
ApproverName: "Craig White",
ApproverEmail: "craig.white@platformsofpower.com"
},
{
ApprovalStep: 1,
ApprovalOrder: 2,
ApproverName: "Luke Skywalker",
ApproverEmail: "luke.skywalker@platformsofpower.com"
}
)
The ApprovalOrder column is an integer to dictate the order of preference for any approvals.
Resolution
As I have an active out of office message, we need to ensure our app automatically picks up Luke Skywalker as the primary instead of me. We’ll use colApprovers to drive the logic needed.
We could use the following code on a behavioural property (such as OnVisible or OnSelect) to automatically detect and set a variable. Here, I’m using a With function but you can use a number of different ways to get to the same outcome:
With(
{
/*
Does the primary approver have an active out of office?
If it's not Blank, set to true (person is out of office)
If not Blank, set to false (person is not out of office) */
tvPrimaryApproverOOO: !IsBlank(
Office365Outlook.GetMailTips(
Index(
colApprovers,1).ApproverEmail
).AutomaticReplies.Message
)
},
If(
// If primary is OOO, get secondary approver
tvPrimaryApproverOOO,
Set(
gvApprover,
Index(colApprovers,2).ApproverEmail
),
// Else, get primary approver
Set(
gvApprover,
Index(colApprovers,1).ApproverEmail
)
)
)
You can use either GetMailTips or GetMailTipsV2 methods for the above, as setting a variable requires a behavioural property of some kind.
We can provide a nice experience for app users and visualise who the approval will be going to. Adding a gallery, we can use the following Power Fx in the Items property to determine if each approver has an active out of office. If blank, return false, else return true.
From here-on, we can only use the GetMailTips approach as what we’re trying to achieve is non-behavioural:
// Items property of our gallery
AddColumns(
colApprovers,
'Out of Office',
!IsBlank(Office365Outlook.GetMailTips(ApproverEmail).AutomaticReplies.Message)
)
Adding a label to the gallery, we can show the output of the additional column:
We could take it up a notch, adding an icon to the gallery and setting the visible property to the output of the column:
Depending on the scenario, we could even configure the tooltip property of the icon to show the out of office message. We’d have to use the Plain Text function here:
Getting out of office messages directly into a canvas app can be really useful. Hopefully the tips above will help if you need to do the same.
Thanks for reading. If you liked this article and want to receive more helpful tips about the Power Platform, don’t forget to subscribe or follow me on socials 😊