How to Show Multiple Attachments in Adaptive Card Power Automate: A Step-by-Step Guide
Image by Swahili - hkhazo.biz.id

How to Show Multiple Attachments in Adaptive Card Power Automate: A Step-by-Step Guide

Posted on

Power Automate (formerly Microsoft Flow) has revolutionized the way we automate tasks and workflows. One of its most powerful features is the Adaptive Card, which allows us to create interactive and dynamic interfaces for our users. However, when it comes to handling multiple attachments, things can get a bit tricky. Fear not, dear reader, for we’re about to dive into the world of Adaptive Cards and show you exactly how to display multiple attachments in Power Automate.

What are Adaptive Cards?

Before we dive into the nitty-gritty of showing multiple attachments, let’s take a quick detour to understand what Adaptive Cards are.

Adaptive Cards are a powerful feature in Power Automate that allows you to create interactive and dynamic interfaces for your users. They’re essentially a way to present information in a flexible and visually appealing way. You can think of them as a digital container that can hold a variety of content, such as text, images, videos, and even interactive elements like buttons and forms.

The Problem: Handling Multiple Attachments

So, what’s the problem with showing multiple attachments in Adaptive Cards? Well, by default, Power Automate only allows you to attach a single file to an Adaptive Card. This can be a major limitation, especially when you need to share multiple files with your users.

But fear not, dear reader, for we’re about to show you a clever workaround to display multiple attachments in Adaptive Cards.

Solution: Using an Array of Attachments

The secret to displaying multiple attachments in Adaptive Cards lies in using an array of attachments. In Power Automate, you can create an array variable and store multiple file objects in it. Then, you can loop through the array and attach each file to the Adaptive Card.

Step 1: Create an Array Variable

First, create a new variable in Power Automate and set its type to “Array”. Name it something like “AttachmentsArray”. This will be the container for our multiple attachments.


{
  "type": "array",
  "value": [
    {
      "name": "attachment1.pdf",
      "contentBytes": "/base64 encoded content bytes/"
    },
    {
      "name": "attachment2.docx",
      "contentBytes": "base64 encoded content bytes/"
    },
    {
      "name": "attachment3.xlsx",
      "contentBytes": "base64 encoded content bytes/"
    }
  ]
}

Step 2: Loop Through the Array and Attach Files

Next, create a “For each” loop in Power Automate and set the array variable as the input. This will allow us to loop through each attachment in the array and attach it to the Adaptive Card.

Inside the loop, add an “Add an attachment” action and set the attachment properties to the current item in the array. Make sure to set the “IsInline” property to “True” so that the attachment is displayed inline in the Adaptive Card.


{
  "type": "object",
  "properties": {
    "attachments": {
      "type": "array",
      "items": {
        "$ref": "#/properties/attachment"
      }
    },
    "attachment": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "contentType": {
          "type": "string"
        },
        "contentBytes": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "contentType",
        "contentBytes"
      ]
    }
  }
}

Step 3: Configure the Adaptive Card

Finally, configure the Adaptive Card to display the multiple attachments. Add a “Text” element to the card and set its text to an expression that loops through the array of attachments and displays their names.


{
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "TextBlock",
      "text": "=join(' ', attachmentsArray.map(item => item.name))"
    }
  ]
}

This will create a list of attachment names separated by commas.

Displaying Multiple Attachments in Adaptive Cards: The End Result

And there you have it, folks! With these simple steps, you can now display multiple attachments in Adaptive Cards using Power Automate.

Here’s an example of what the end result might look like:

Attachment 1 Attachment 2 Attachment 3
attachment1.pdf, attachment2.docx, attachment3.xlsx

Conclusion

In this article, we’ve shown you how to display multiple attachments in Adaptive Cards using Power Automate. By using an array of attachments and looping through it, you can attach multiple files to an Adaptive Card and display them in a visually appealing way.

With this newfound knowledge, you can take your Power Automate workflows to the next level and create more engaging and interactive interfaces for your users.

FAQs

Q: Can I attach multiple files of different types?

A: Yes, you can attach files of different types, such as PDFs, Word documents, Excel spreadsheets, and more.

Q: How many attachments can I display in an Adaptive Card?

A: There’s no limit to the number of attachments you can display in an Adaptive Card, but keep in mind that too many attachments might make the card look cluttered and difficult to navigate.

Q: Can I display attachments in a specific order?

A: Yes, you can sort the array of attachments before looping through it to display them in a specific order.

We hope this article has been informative and helpful. Happy automating!

Here are 5 Questions and Answers about “How to show Multiple Attachment in Adaptive Card Power Automate”:

Frequently Asked Question

Get answers to your most pressing questions about showcasing multiple attachments in Adaptive Cards using Power Automate.

How do I add multiple attachments to an Adaptive Card in Power Automate?

To add multiple attachments to an Adaptive Card in Power Automate, you can use the ‘Attachments’ property and pass an array of attachment objects. Each attachment object should contain the file name, file type, and file content. You can use the ‘Add attachment’ action in Power Automate to create an array of attachment objects and then pass it to the Adaptive Card.

Can I display multiple attachments in a single Adaptive Card action?

Yes, you can display multiple attachments in a single Adaptive Card action. To do this, you need to use the ‘Carousel’ layout in your Adaptive Card and add an ‘Attachment’ element for each attachment you want to display. You can then bind the attachment array to the ‘Attachments’ property of the Adaptive Card.

How do I bind an array of attachments to an Adaptive Card in Power Automate?

To bind an array of attachments to an Adaptive Card in Power Automate, you need to use the ‘Bind to an array’ option in the Adaptive Card designer. Select the ‘Attachments’ property and then choose the array variable that contains the attachment objects. You can then use the ‘Attachments’ property to display the attachments in the Adaptive Card.

Can I control the order of attachments displayed in an Adaptive Card?

Yes, you can control the order of attachments displayed in an Adaptive Card. To do this, you can sort the attachment array in the desired order before binding it to the Adaptive Card. You can use the ‘Sort array’ action in Power Automate to sort the attachment array based on properties such as file name, file type, or file size.

Are there any limitations to displaying multiple attachments in an Adaptive Card?

Yes, there are limitations to displaying multiple attachments in an Adaptive Card. For example, some channels such as Microsoft Teams may have limitations on the number of attachments that can be displayed in a single Adaptive Card. Additionally, large attachments may impact the performance of the Adaptive Card. It’s essential to test your Adaptive Card with multiple attachments to ensure it meets your requirements.

Let me know if you need anything else!

Leave a Reply

Your email address will not be published. Required fields are marked *