Post

#PowerPlatformTip 126: 'User Context for Automated Tasks'

#PowerPlatformTip 126: 'User Context for Automated Tasks'

TL;DR: One flow with the Power Apps (V2) trigger and the action Set up automatic replies (V2) sets the out-of-office reply for whoever clicks the button in your app. The trick: in the flow’s Run only users settings, set the Office 365 Outlook connection to Provided by run-only user. A scheduled flow only sends the reminder with the app link.

💡 Challenge

You want to automate tasks like setting an out-of-office reply in Outlook, but they must run in each user’s own mailbox. A scheduled flow always runs with its owner’s connections, so it can only change the owner’s mailbox. Building one flow per user doesn’t scale, and users want to adjust the text before it’s set.

✅ Solution

Split the job:

  • A Power App collects the user’s input, such as the reply text and the dates.
  • One instant flow with the Power Apps (V2) trigger sets the reply. Its Outlook connection is provided by the run-only user, so the flow acts as the person who runs it and works with their mailbox.
  • A scheduled flow sends a reminder with the app link, for example every morning.

🔧 How It’s Done

1. Build the flow that does the work.

🔸 Create an instant cloud flow with the Power Apps (V2) trigger and three inputs: ReplyText (text), StartTime and EndTime (text in ISO format).

🔸 Add Office 365 Outlook Set up automatic replies (V2): Status = Scheduled, External Audience = All (or ContactsOnly / None), Scheduled start time = StartTime, Scheduled end time = EndTime, TimeZone = for example W. Europe Standard Time, Internal Reply Message and External Reply Message = ReplyText.

2. Switch the connection to the user.

🔸 On the flow’s details page, open Run only users > Edit.

🔸 For the Office 365 Outlook connection select Provided by run-only user. From now on the flow uses the connection of the person who runs it, and the action changes that person’s mailbox.

🔸 If the flow is already added to the app, refresh it in the app (or remove and add it again) and save the app, otherwise the app keeps the old connection setting.

3. Build the app.

🔸 Add a text input txtReply, two date pickers dpStart and dpEnd, and the flow via Power Automate > Add flow.

🔸 Prefill the text, for example Default of txtReply: "Hello, I'm out of office. I'll answer your message when I'm back. Regards, " & User().FullName.

🔸 Button OnSelect:

SetAutoReply.Run(
    txtReply.Text,
    Text(dpStart.SelectedDate, "yyyy-mm-dd") & "T00:00:00",
    Text(dpEnd.SelectedDate, "yyyy-mm-dd") & "T23:59:00"
);
Notify("Automatic reply is set.", NotificationType.Success)

🔸 Share the app with the users. On first use, Power Apps asks each user to sign in to the Outlook connection.

4. Schedule the reminder.

🔸 A second flow with the Recurrence trigger, for example Fridays at 14:00, sends a Teams message or an email with the app’s web link to the users who should set a reply.

🎉 Result

Each user gets the reminder, opens the app, adjusts the text and clicks the button. The flow sets the reply in their mailbox. One app, one flow, no per-user copies.

🌟 Key Advantages

🔸 Runs in the user’s context: the action uses the connection of whoever runs the flow.

🔸 One flow for everyone: central maintenance, no per-user copies.

🔸 User stays in control: text and dates are reviewed before anything changes.

🎥 Video Tutorial

🛠️ FAQ

1. How do I ensure the flow runs with the user’s permissions?

Set the connection to Provided by run-only user in Run only users. A connection configured like this is provided by the user who runs the flow and lets the flow act as that user. Embedded connections, by contrast, always act as the person who created them.

2. Can a scheduled flow set the replies for all users without the app?

Not with the standard Outlook action. A scheduled flow has no “current user”, it runs with its owner’s connections. The user has to trigger the instant flow, which is exactly what the app does.

3. Which other tasks work with this pattern?

Everything a user does with their own connection: posting a Teams message as themselves, creating events in their calendar, or saving files to their OneDrive. Switch each of those connections to Provided by run-only user.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.