Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding select-current-user-by-default-in-people-picke blog #3

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions content/blog/select-current-user-by-default-in-people-picker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
+++
title = 'Select Current User by Default in People Picker'
date = 2023-11-19T15:32:05+01:00
draft = false
+++

In case you are building a canvas app in Power Apps and you need to have the current user selected in a people picker combobo box by default, this is a quick and easy way to achieve this.

## Create a people picker combobox
First insert a combo box control in your app and set its' **Items** property to:
```
Choices(DataSource.PersonTypeColumn)
```
In the above formula *DataSource* referes to data source such as a Dataverse table or SharePoint list and *PersonTypeColumn* refers to a column inside that data source which is of type Person/Group.

The next step is to make sure the combo box is displaying the information by selecting **Edit** next to **Fields** in the properties pane on the left side of Power Apps studio, selecting the **Person** option under **Layout** and making sure the relevant columns are selected for **Image**, **Primary text** and **Secondary text**.

![Screenshot of the Power Apps studio showing how to set up a people picker comobobox as explained in the text before the screenshot.](/images/PeoplePicker.PNG "How to set up a peoplepicker combobox.")

## Selecting the current user by default
The same `Choices()` function can be used to select the current user by default in the **DefaultSelectedItems** property of the people picker combo box:
```
First(Choices(DataSource.PersonTypeColumn, User().Email))
```
By using the `User()` function in the second argument of the `Choices()` function, the possible values are filtered, returning only those that match the email address of the current user. To then convert the returned table into a single record, the `First()` function is used.

As a result, whenever the people picker combo box is reset, the current user is selected:

![Screenshot of the Power Apps studio, showing the result of the above text on how to set .](/images/PeoplePickerUserDefault.PNG "Select current user by default in a peoplepicker combobox")

## Added benefit
In some cases the DisplayName column will contain a different value than what `User().FullName` returns. An added benefit of this method over other methods is that a consistant value for the displayname of the current user is displayed.
16 changes: 14 additions & 2 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,17 @@

[params]
title = "Power Platform Community Solutions"
author = "HelmUpgradeBot"
description = "Answers to recurring questions"
description = "Answers to recurring questions"
mainSections = ["blog"]
author = "BCBuizer"
profilePicture = "images/profile_pic.png"

[[params.socialIcons]]
icon = "fab fa-linkedin"
title = "Linkedin"
url = "https://www.linkedin.com/in/barend-buizer/"

[[params.socialIcons]]
icon = "fas fa-light fa-users"
title = "Microsoft Power Platform Community"
url = "https://powerusers.microsoft.com/t5/user/viewprofilepage/user-id/266500/"
Binary file added static/images/PeoplePicker.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/PeoplePickerUserDefault.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/profile_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading