Setting Selected Text in a PA Dropdown

dropdownA common question that I’ve run into again lately is how can I set the Selected or Selected Text property of a dropdown control in a Canvas App when there is NO Selected property?  The key to solving this problem is understanding the interaction between two other aspects in Power Apps.  They are the default property of the Dropdown and the Reset() function in Power Apps.  Lets look at how each of these work and how they interact.

Dropdown Default Property

Setting the initial value in a dropdown is as easy as setting the default property of the control.  When the control first loads it will look at the default property to set the initial value of the controls. The problem is that once a user has interacted with the control the default setting will be ignored. This is where the Reset() function comes in.

Reset() Function

The Reset() function in Power Apps is specifically designed to reset a given control back to their Default settings.  Adding Reset(<<DropDown>>); to the end of an OnSelect that Patches or Submits a form will clear the user’s input and reset the Dropdown back to its original default value.

Try it Yourself

  1. Add a Dropdown and a Button to a Screen in a Power App
  2. Set the Default property of the Dropdown to “2”
  3. Type reset(Dropdown1) into the OnSelect Property of the Button

When you run the app the dropdown will default to 2. Use the dropdown to select 3 as the chosen value. Navigate to a different screen and back again.  The dropdown will be set to 3. Press the button.  The dropdown selected value will change to 2

This functionality works on most controls with minor variations.  Its the same for TextInput boxes, but for ComboBoxes you set DefaultSelectedItems to a record containing the value of the default selection.

Renewed as an MVP 15th Year

We had to wait a few extra days this year to find out if we were re-awarded or not. Microsoft sent an email on July 1st saying that the announcement had been delayed until July 5th. But I was honored to get the official notice that my MVP status has officially been re-awarded for the 15th year. It just doesn’t seen like its been that long. Every year brings new excitement and new challenges. There is still so much to be learned. I continue to feel honored and grateful for Microsoft’s recognition of my contributions to the community for another year.

But now its time to plan for the next year.  It was a bit strange to be back speaking at conferences in person this year, but attendance has been good and I’ve been impressed by the questions at my workshops and sessions. The main change has been that the SPFest conference has changed its name to EduCon and has added more Power Platform coverage under the name PwrCon. I’ll be speaking at the Dallas conference in August and the Chicago conference in September. I’ll also be back at the North American Collaboration summit in Branson, MO in October.

I am continuing to focus more on working with the Power Platform particularly as it applies to SharePoint and Teams.  This year I was honored to be named as one of three Triple Super Users in the Power Apps, Power Automate, and Power Virtual Agents community forums. These continue to be a hot technology form Microsoft, especially for people using Microsoft 365 and Teams.

So here’s to another year as an MVP. I’m really looking forward to it.

Dataverse for Teams–Demo Code Solution

EduConPwrCon This post is a week overdue.  I was in Seattle last week to present 2 workshops and 3 talks.  One of the workshops and one of the talks was on how to use Dataverse for Teams. Many of the attendees asked if they could have a copy of the demos that I used during the talks. Below you will find a link to the solution that you can import into Power Apps in Teams to have copies of the Power App, Power Virtual Agent Bot, and Power Automate flows in the demo.  You can import the solution using the Power Apps client inside Teams.  Navigate to the Build Tab and select the See All link.

Dataverse4TeamsImport

Here’s the link to the Solution File:
https://www.dontpapanic.com/Download/Dataverse4Teams_1_0_0_3.zip

Send One Email per Person in a Mixed List

apply to eachOne of the most common questions I see on the Power Platform forums is: “I have a data source that contains a list of information that I need to send as an HTML table to the individual mentioned in each item. But its sending more than one email to each person.  How do I get it to send just one email for each person with all the records for that person?”  In this post I’ll demonstrate a general method to accomplish that goal using Power Automate. For this example we’ll use a simple list from SharePoint, but the same technique should work for any data source that can be sorted.  Here’s our list:

list

We want to send a table with the hours spent by each programmer and their current status to each Project Manager.

Step#1 – Retrieve the records from data source.  Sort them based on the field that references the person, in this case Project Manager. This will not work if the field includes multiple people. Here’s a screenshot of that part of the flow.

list1

Step#2 – The next step is to get a list of the distinct project managers in the results we have retrieved.  Unfortunately, Power Automate doesn’t have a Distinct() function.  But we can achieve the same result using a combination of a Data Select action and the Union() function. When we combine the Data Select array with itself using Union() we will get an array that has a single instance of each unique record in the Data Select array. In this case a list of each Project Manager’s Email address.

Distinct1

Step#3 – Now that we have an array of distinct Project Manager Emails we can run an Apply to Each loop on each Email, extract the records for that manager, create a table and send the email. Here’s what the overall Loop looks like then we’ll review each step. The loop runs on the array produced by the union in the last Compose action.

loop 1

Loop Step #1 – The first thing we do inside the loop is filter the original set of records to create an array of records where the Project Manager’s Email in the record matches the current item’s email.  Since we stored the email as a record using the data select we need to retrieve it using JSON notation in the Expressions tab.  The JSON will be for the current loop item ‘PM’ property.  items(‘Apply_to_each’)?[‘PM’]

apply1

Loop Step#2 – Now that we have the records for one of the Project Managers we need to turn them into a table. First we need to use Parse JSON to re-apply a schema to the filtered records so we can access individual columns.  We parse the Body output of the filter array action. Run the flow once after adding the Parse JSON and use the output from the filter array to generate a JSON schema.

apply2

Loop Step#3 – Now we are ready to create the HTML table to embed in the email. Use the Create HTML Table set for custom and map the columns you want in the table from the Parse JSON output. I used the programmer’s displayName, Hours, Status, and Project columns. You may have multiple columns with the same name, like DisplayName.  These represent the embedded properties in objects.  For example the DisplayName might be for the Project Manager, the Programmer, or the person who created the item in the list. You can tell which one you added by hovering over the column and looking at the JSON.

apply3

Loop Step#4 – The last step in the loop is to send the email. Use the same JSON that you used to filter the array in Loop Step#1, since that is the email address of the Project manager. Fill out the subject and Body of the email with whatever information you want, including the HTML table you just created.

Apply4

That’s all you need.  The loop will now process each Person in the list and send one email to each with the correct information. I’m sure your list will be different, but the steps should be essentially the same.

Running a Recurrence Flow on Weekdays Only

RecurrenceRecurrence Triggers are essential for a wide variety of scenarios.  They can be used to run a flow on a specific date and time.  Or they can be used to run a flow on a recurring schedule, like once a day or once a month.  They can even be used in situations where  a process needs to run longer than the 30 day timeout limit on flows.

But what if your recurring schedule has exceptions.  For example, you might want to run it on the first Monday of each month or only on weekdays.  How can we use the recurrence trigger to handle these more complicated scenarios?

One possible solution is to trigger the flow on a simple schedule, like daily, and then test to see if its the right day.  If it is proceed with the flow, but if its not just exit.  This does work, but it consumes a lot of flow runs that are unnecessary.  Not only is this inefficient it may cause an issue with the limits on API calls in a 24 hour period.  It would be much better if we could take these conditions into account BEFORE the flow triggers.  But we can’t always reach that level of granularity in the trigger configuration itself. But we can if we use the trigger conditions available under settings.

Let’s look at a specific scenario.  I want this flow to trigger on each workday of the month. I start out by creating a flow with a trigger set to fire once a day.  This will create a flow that runs everyday of the month.  So far the trigger will look like this.

RecurrenceTrigger

Next I need an appropriate filter that will limit the trigger to only fire on Monday thru Friday.  If you aren’t familiar with how to write that filter I suggest using a ‘Filter array’ action to put it together.  After adding a ‘Filter array’ action to your flow fill in the left side of the comparison with the following formula:

dayOfWeek(utcNow())

That will take the current date and convert it to a number for the day of the week.  Monday = 1, Tuesday = 2, etc. Now finish the condition by choosing ‘is less than or equal to’ in the middle and enter ‘5’ on the right.  We haven’t filled in the Array to filter, but since all we want is the formula that’s OK.  We’ll be deleting this action after we copy the formula.  Your action should now look like this.

filter array

Now comes the trick that makes this worthwhile.  Click on the ‘Edit in advanced mode’ link. The action will now look like the following.

filter array advanced

The formula we need is the one highlighted in yellow.  Copy that formula to your clipboard and delete the ‘Filter array’ action.  Our finished flow doesn’t actually use it.  Now open the settings dialog for the recurrence trigger using the ellipses (…) menu on the trigger. Click the + Add link under Trigger Conditions and paste the formula you copied into the textbox that appears.  Your Settings should now look like this.

Settings

You can now click Done and your flow trigger each day if it is a Monday through Friday.  It will not trigger on Saturday, day 6, or Sunday, day 7. Using trigger conditions you can fine tune the schedule of your recurrence trigger to only fire when you want it to.