Goal
Our end goal here is to post an adaptive card to 2 different departments for approval. Each department will be presented with a different set of rejection reasons based on their department dynamically. These rejection reasons are being fetched dynamically from the SharePoint List and are being appended to the adaptive cards. This eliminates the need to modify the adaptive cards each time the data in the SharePoint list is modified.
Pre-Requisites
- An account with license for below services:
- SharePoint Online (Plan 1/Plan 2)
- Microsoft Teams
- Microsoft Power Automate Free
- A SharePoint Online site with contribute access to the account in use
- A SharePoint List that will be used as a data input source. In our case, we are using a list called Equipment Request with the below columns:
- Title (this is the default column)
- Status (Single line of text)
- Default value has been set to Pending
- A SharePoint List that will be used as a source to fetch dynamic data for reason based on department. In our case, we are using a list called Rejection Reason with the below columns:
- Department (We have renamed Title column to Department)
- Rejection Reason (Single line of text)
Steps to perform:
1. Create a SharePoint List Equipment Request. We will be using this list to add content and trigger a flow (when an item is created or modified) that will post an adaptive card. We will use the below columns in the list:
-
- Title (this is the default column)
- Status (Single line of text)
- Default value has been set to Pending
- Create another SharePoint List Rejection Reason that will be used to dynamically render rejection reasons in the adaptive cards basis the department the card is being posted to. We will use the below columns in the list:
- Department (We have renamed Title column to Department)
- Rejection Reason (Single line of text)
- Populate data in the Rejection Reason list since we will be using data from this list in our adaptive cards. For our case, below is the sample data table:
7. Initialize another set variables HRReasons & ITReasons (Array). We will be using these variables to append data to the adaptive card.
9. Get List Items (with Filter Query). Here we will filter and fetch rejection reasons only for “Human Resource” department (for demo purpose). Here you can dynamically fetch department for a given user and apply that filter for this query accordingly.
- Below is the JSON code that we used for composing our adaptive card:
{
“type”: “AdaptiveCard”,
“$schema”: “http://adaptivecards.io/schemas/adaptive-card.json”,
“version”: “1.2”,
“body”: [
{
“type”: “TextBlock”,
“text”: “A New Request has been submitted by @{triggerOutputs()?[‘body/Author/DisplayName’]}”,
“wrap”: true,
“id”: “Request_Head”,
“size”: “Medium”,
“weight”: “Bolder”,
“horizontalAlignment”: “Center”
},
{
“type”: “TextBlock”,
“text”: “@{triggerOutputs()?[‘body/Title’]}”,
“wrap”: true,
“id”: “Request_Body”
}
],
“actions”: [
{
“type”: “Action.Submit”,
“title”: “Approve”,
“id”: “Approve”,
“style”: “positive”
},
{
“type”: “Action.ShowCard”,
“title”: “Reject”,
“card”: {
“type”: “AdaptiveCard”,
“body”: [
{
“type”: “TextBlock”,
“text”: “Please select a reason for rejecting the request.”,
“wrap”: true,
“id”: “Rejection_Heading”
},
{
“type”: “Input.ChoiceSet”,
“choices”: @{variables(‘HRReasons’)},
“placeholder”: “Placeholder text”,
“style”: “expanded”,
“value”: “@{body(‘Get_Human_Resource_Rejection_Reasons_items_from_Rejection_Reason_List’)[‘value’][0][‘RR’]}”,
“id”: “Choices”
}
],
“actions”: [
{
“type”: “Action.Submit”,
“title”: “Reject”,
“id”: “Rejected”,
“style”: “destructive”
}
]
},
“id”: “Reject”,
“style”: “destructive”
}
],
“id”: “Adaptive_Card”
}
- Highlighted sections in the JSON above is the Dynamic content or expression that has been used to compose an adaptive card
12. Now we will post an Adaptive Card to the Human Resource Channel & Wait for a response
17. We will capture the response of the HR approver in the HRResponse variable
@{body(‘Post_an_Adaptive_Card_to_IT_Helpdesk_Teams_channel_and_wait_for_a_response’)[‘submitActionId’]}
27. We will then update the status of the request with the response of the next approval
Conclusion
We just saw how we can dynamically filter values and present them as dynamic options in an adaptive card.
In this demo the First Approval request goes to the Human Resource Channel in the Operations Team. Once the request is approved by the Human Resource Team, it is then forwarded for Second level Approval & Fulfilment to the IT Helpdesk Channel in the Operations Team. If the request is rejected by the HR, it will not be presented to the IT Helpdesk for fulfilment.
This kind of dynamic filtering can be achieved by using content from SharePoint Lists.
Written By
Akhil Ohri
(Microsoft 365 Consultant)
Peer Reviewed By
Jasjit Chopra
(Microsoft 365 Consultant)