Posting adaptive cards to Microsoft Teams upon winning an Opportunity

Sending
User Review
0 (0 votes)

Introduction

Most of you might already be aware of the fact that we can use Power Automate to automatically push/send the notification to the Microsoft Teams channel. In this blog, let’s step it up and understand how we can create our own adaptive cards and use Power Automate to post the card to the Microsoft Teams channel. All of these are going to be triggered on the events in Dataverse. So, the scenario is that this power automated flow will run when the opportunity is “Won” and this will send the notification to the owner of the opportunity in Microsoft Teams. In other words, we are going to grab the required data from opportunity and put that into adaptive cards further to be sent to MS Teams. Let’s see the step-by-step process of the same.

First, we will start designing the adaptive cards, for this go to: https://adaptivecards.io/designer

Click on “Samples”

Posting adaptive cards to Microsoft Teams upon opportunity win

Now, have a look at all of the available sample cards and pick one that you can start with.

Posting adaptive cards to Microsoft Teams upon opportunity win

Here we will choose the below one and click on “Try it Yourself”.

Posting adaptive cards to Microsoft Teams upon opportunity win

You will see the preview of the adaptive card and next to that are the card structure and element properties along with the payload editor just at the bottom. This is nothing but JSON that we will use later in our power automated flow.

Posting adaptive cards to Microsoft Teams upon opportunity win

Now let’s first get rid of the fields that we do not require from the selected sample adaptive card.

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

Next, we will edit the below details, but before that, we need to make sure to select the host application that we are going to show this adaptive card in.

Posting adaptive cards to Microsoft Teams upon opportunity win

Select the host application from the list – since we are using Microsoft Teams with a light background, to show this card we’ll select the below option from the list.

Posting adaptive cards to Microsoft Teams upon opportunity win

Now let’s edit the field as shown below –

We also want to tag the owner of an opportunity in the adaptive card notification being sent to Microsoft Teams, so we will put it as shown below:

Posting adaptive cards to Microsoft Teams upon opportunity win

Topic of an opportunity to be displayed in the teams, so below is how it can be mentioned:

Posting adaptive cards to Microsoft Teams upon opportunity win

Let’s show the total revenue of the opportunity that is won.

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

Note: We are going to set the dynamic values for the owner, topic, and annual revenue of the opportunity soon in the Power Automate flow, that’s the reason we have placed them into “<..>” for now so that we can recognize them easily for the dynamic selection later on in the automated flow.

To make the adaptive card more interactive and we can add the image/gif as shown below:

From the card elements on the left-hand side, simply drag the “Image” element and drop it on the adaptive card, and set the URL of an image to show the image of your choice.

Posting adaptive cards to Microsoft Teams upon opportunity win

Once you set the Url, it will look like below:

Posting adaptive cards to Microsoft Teams upon opportunity win

Next, we have to enable the provision allowing users to open the opportunity record (won) directly from the Microsoft Teams, so we will add a link option to this adaptive card. Click on the edge of the card and further click “Add an action”.

Posting adaptive cards to Microsoft Teams upon opportunity win

Select the below option:

Posting adaptive cards to Microsoft Teams upon opportunity win

And give a relevant names to the action.

Posting adaptive cards to Microsoft Teams upon opportunity win

Set the URL of the opportunity record that is going to be won, so when the user clicks on “Open Opportunity” on adaptive cards in teams, it will open the actual opportunity record that is won.

For this, we are going to get the partial Url of the opportunity record. This is how it should be set –

https://aprilcrmbusiness.crm3.dynamics.com/main.aspx?appid=9448558c-5098-eb11-b1ac-000d3af4672e&pagetype=entityrecord&etn=opportunity&id=<oppid>

We are copying only till “id” in the Url of an opportunity and not over the last part of the Url–

Posting adaptive cards to Microsoft Teams upon opportunity win

Again, we are going to dynamically select the opportunity at the place highlighted above, so let’s copy the URL to the Url field as shown in the below image.

Posting adaptive cards to Microsoft Teams upon opportunity win

We have successfully designed our adaptive cards so far to use in our power automated flow, now let’s design our Power Automate flow.

Choose to create a new automated cloud flow.

Posting adaptive cards to Microsoft Teams upon opportunity win

Skip this over. We can now name the flow and configure the steps going forward.

Posting adaptive cards to Microsoft Teams upon opportunity win

Select the below trigger.

Posting adaptive cards to Microsoft Teams upon opportunity win

Since we want to trigger the flow on status update of an opportunity to “Won”, we are putting the value as shown below:

Posting adaptive cards to Microsoft Teams upon opportunity win

Now, add a new step.

Posting adaptive cards to Microsoft Teams upon opportunity win

Next, we have to get the information from the owner of an opportunity, so we will select the below operation and set the appropriate values to the fields.

Posting adaptive cards to Microsoft Teams upon opportunity winPosting adaptive cards to Microsoft Teams upon opportunity win

As we want to also tag the owner of the opportunity in the adaptive card that will be posted to Microsoft Teams, we will perform the below step to get the mentioned token which will tag the owner user in the message in adaptive cards.

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

Here, it is going to be the user name from the previous step.

Posting adaptive cards to Microsoft Teams upon opportunity win

Let’s proceed to the last step now, as we want to post the adaptive card to the Microsoft Teams channel, we will design the step as shown below:

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

We are choosing to post the adaptive card to the Microsoft Teams channel with a flow bot. Along with this, we will also have to put the JSON of the adaptive card into the step. So, configure the step as shown below, but before this, let’s go back to adaptive card designer and copy the card payload (JSON) as seen below:

Posting adaptive cards to Microsoft Teams upon opportunity win

Come back to flow, and set the fields as shown below:

Posting adaptive cards to Microsoft Teams upon opportunity win

Now in the “Adaptive Card” field, paste the JSON (Card payload) that we copied earlier.

Posting adaptive cards to Microsoft Teams upon opportunity win

We will have to do some dynamic selection over here in this JSON.

At the place of “<Owner>”

Posting adaptive cards to Microsoft Teams upon opportunity win

Select –

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

Do the dynamic selection for the topic of the opportunity.

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

For Revenue,

Posting adaptive cards to Microsoft Teams upon opportunity win

Select the dynamic value.

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

Lastly, since we want to be able to open the actual won opportunity record from the adaptive card in teams, we will dynamically select the opportunity.

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

We have completed designing the flow, now let’s save it and test it.

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

After clicking on “Test”, go back to CRM and win an opportunity having some value in actual revenue.

Posting adaptive cards to Microsoft Teams upon opportunity win

Posting adaptive cards to Microsoft Teams upon opportunity win

You will see the channel showing one notification in teams.

Posting adaptive cards to Microsoft Teams upon opportunity win

If you further open it, it will show you the adaptive cards with all the details that we have dynamically set in our flow and configured for our adaptive card.

Posting adaptive cards to Microsoft Teams upon opportunity win

If you want to see the Opportunity record, simply click on “Open Opportunity”, it will navigate the user to the opportunity record that is won earlier.

Posting adaptive cards to Microsoft Teams upon opportunity winPosting adaptive cards to Microsoft Teams upon opportunity win

Conclusion

As illustrated, we have been able to successfully design the adaptive cards and post it onto the Microsoft Teams with the help of MS Teams integration using Power Automate.