In this blog, we will be learning about People Picker in Adaptive Cards.
People Picker is an input control in Adaptive Card. It allows users to quickly search and select valid user accounts for peoples within the organization.
People Picker supports the following features:
- Searches single or multiple users.
- Selects single or multiple users.
- Reassigns to single or multiple users.
- Prepopulates the name of selected users.
Implementation of People Picker
People Picker in Adaptive Cards is implemented as an extension of the Input.ChoiceSet control.
Schema
The following properties are additions to the Input.ChoiceSet schema to enable People Picker experience on the Adaptive Card.
Input.ChoiceSet control
The choices.data property is supported in version 1.6; however, in my testing, it also worked for version 1.4. The JSON format data is passed into the property.
Property | Type | Required | Description |
---|---|---|---|
choices.data | Data.Query | No | Enables dynamic auto complete for different user types, by fetching results from the dataset specified. |
Data.Query
Property | Type | Required | Description |
---|---|---|---|
dataset | String | Yes | The type of data that must be fetched dynamically. |
dataset
The following table provides predefined values as dataset for people picker:
dataset | Search Scope |
---|---|
graph.microsoft.com/users | Search all members across the organization. |
graph.microsoft.com/users?scope=currentContext | Search within the members of the current conversation, such as chat or channel in which the particular card is sent. |
Data Submission
We can use Action.Submit or Action.Execute to submit selected user data. The payload received is a list of Microsoft Entra IDs or the IDs provided in the static list. In People Picker, when a user is selected in the control, the Microsoft Entra ID of the user is the value sent back. The Microsoft Entra ID is a string and uniquely identifies a user in the directory.
Create Flow
1). Sign in to Power Automate
2). Open the flow, click on the Create option, and select "Instant Cloud Flow".
Enter Flow name.
Choose the flow trigger as "Manually trigger a flow".
Click on the Create button.
3). Add an action "Post adaptive card and wait for a response".
Add mandatory parameter values as shown in below image.
In this step an Adaptive Card with People Picker control will be sent to user in MS Teams chat. It will wait till the user has search & selected the user(s) and clicked on 'Save' button.
4). Add a loop "Apply to each" and set input value "Select an output from previous steps" as below
split(body('Post_adaptive_card_and_wait_for_a_response')?['data']?['peoplePickerChoiceSetControlID'],',')
Then add an action "Get user profile (V2)" and enter User (UPN) value as current item.
Here, we are retrieving the user(s) that has been selected and submitted from above step. When a user is selected in the control, the Microsoft Entra ID (Azure Active Directory) of the user is the value sent back. The value will be comma separated user ID's if multi select is enabled.
To compare, we will iterate over the values and verify if the chosen user matches the one we have received.
Repeat above step for all the four People Picker controls added in Adaptive card.
Now we will discuss how to create Adaptive Card parameter value.
5). Open Adaptive Cards Designer portal.
Select host app as "Microsoft Teams" and Target version as 1.4
Then, create the Adaptive card design according to your requirements.
Once Adaptive Card design is complete. Click on "Copy card payload" and paste it into the Adaptive Card parameter value (Step 3)
People Picker - CARD PAYLOAD |
---|
|
6). Complete flow with all the actions will look like below.
Now it's time to test the flow. Manually run the flow and wait for sometime.
People Picker in Adaptive Card output for Teams desktop application.
People Picker in Adaptive Card output for Teams web application.
Select the user(s) and click Save button.
Refer Adaptive Card blog series:
Adaptive Card: Power Automate send welcome message when new team member added
Adaptive Card: Power Automate send birthday greetings to team members
People Picker in Adaptive Cards
Adaptive Card: Send Form using Adaptive card in MS Teams to group members
I hope this will help all of you! 🧲
Feel free to provide feedback.
🚀 "Happy Coding" 🚀
No comments:
Post a Comment