cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
seussiii
Advocate I
Advocate I

Teams adaptive card - hiding blank or "0" fields

I'm in a pickle and could use some guidance. Hopefully this is the right place. 

 

I have an order form (using Microsoft forms), that includes ~5-6 products. Once filled out it pushes the data to a SP list and then onto an adaptive card in a teams channel for someone to work. I'd like to limit the fields on the card by only showing products that the customer is ordering. Many times its 1-2 of the 6 products with a Qty for each. How would I go about managing that?

 

It could be as simple as displaying text in a text block. I see a field in designer called "Only show when" but have no idea how that would be formatted or how to go about conditioning that based on the data column in sp? Thoughts?

 

image.png

1 ACCEPTED SOLUTION

Accepted Solutions

Hi again!

So I just modeled your SP item as an object variable called myOrderObject... we can work on the mapping from your SP item to this variable by means of a Select action block later

Flow_iterateTextBlock.png

Now I need two more variables:

-myOrderArray maps source object to a format we can iterate through. THe expression I'va assigned as its input is the following:

createArray(setProperty(setProperty(json('{}'),'ProductName','Product1'),'Quantity',variables('myOrderObject')?['Product1']),setProperty(setProperty(json('{}'),'ProductName','Product2'),'Quantity',variables('myOrderObject')?['Product2']),setProperty(setProperty(json('{}'),'ProductName','Product3'),'Quantity',variables('myOrderObject')?['Product3']),setProperty(setProperty(json('{}'),'ProductName','Product4'),'Quantity',variables('myOrderObject')?['Product4']))

-myOrderTextBlockArray will finally store the dynamic TextBlock structure

 

 

Now we have everything set for the iteration via an Apply to Each action block:

Flow_iterateTextBlock_2.png

 

The expression I assigned as 'Append to array' input is the following:

setProperty(setProperty(setProperty(json('{}'),'type','TextBlock'),'spacing', 'None'),'text',concat(item()?['ProductName'],': ',item()?['Quantity']))

 

Please note I add a Dummy Compose action block after the Apply to ech and assign as its input the variable 'myOrderTextBlockArray'. The reason is, If you implement this logic, execute the flow and inspect 'Compose 3' output you will see the content of this variable:

[
  {
    "type": "TextBlock",
    "wrap": true,
    "size": "Medium",
    "text": "Product1: 3 units"
  },
  {
    "type": "TextBlock",
    "wrap": true,
    "size": "Medium",
    "text": "Product4: 2 units"
  }
]

 

And we just need to add 'myOrderTextBlockArray' variable to the Adaptive Card JSON. I just implemented this dummy Adaptive Card

 

Flow_iterateTextBlock_3.png

 

If you need further assigtance pleas let us know

 

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

9 REPLIES 9
efialttes
Super User III
Super User III

Hi!
Do you plan to display each product as a text block?
Thanx!


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



I could. I was thinking that's the easiest way. The rep just needs to know which product types and a qty for each. After that I will have a separate drop down selecting the pricing.

 

I've managed to figure out how to make all that work correctly but i'm just trying to figure out how to hide 0's or blanks so that each card doesnt have every product listed when they only ordered 1-2 of the product types for example. Hope that makes sense.

Hi again
And the zeros/blanks are currently stored in a SP list item right? So in your SP list do you have one column per product quantity requested? If so, is this column of type number?
Thanx!


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



yup! 🙂

Hi again

Let's assume you have 4 different products... current order request 3 Product#1 units and 2 Product#4 units

INside your adaptive card, is it valid according to your requirements to represent the text blocks inside a Container inside your JSON?

AS in this example

 

{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Product#1 Quantity: 3",
"wrap": true,
"size": "Medium"
},

{
"type": "TextBlock",
"text": "Product#4 Quantity: 2",
"wrap": true,
"size": "Medium"
}
]
},

 

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



I currently have it formatted like so

 

"type""TextBlock",
"text""Product 1: xxx",
"spacing""None"
 

xxx is filler for the QTY referenced in SP. Once I get the card designed I'll copy json into PA and add the dynamic references to SP. 

 

Edit: Currently they are not placed inside of a container. I could though I suppose? I haven't used containers much

No problema. Give me some minutes, working on it


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hi again!

So I just modeled your SP item as an object variable called myOrderObject... we can work on the mapping from your SP item to this variable by means of a Select action block later

Flow_iterateTextBlock.png

Now I need two more variables:

-myOrderArray maps source object to a format we can iterate through. THe expression I'va assigned as its input is the following:

createArray(setProperty(setProperty(json('{}'),'ProductName','Product1'),'Quantity',variables('myOrderObject')?['Product1']),setProperty(setProperty(json('{}'),'ProductName','Product2'),'Quantity',variables('myOrderObject')?['Product2']),setProperty(setProperty(json('{}'),'ProductName','Product3'),'Quantity',variables('myOrderObject')?['Product3']),setProperty(setProperty(json('{}'),'ProductName','Product4'),'Quantity',variables('myOrderObject')?['Product4']))

-myOrderTextBlockArray will finally store the dynamic TextBlock structure

 

 

Now we have everything set for the iteration via an Apply to Each action block:

Flow_iterateTextBlock_2.png

 

The expression I assigned as 'Append to array' input is the following:

setProperty(setProperty(setProperty(json('{}'),'type','TextBlock'),'spacing', 'None'),'text',concat(item()?['ProductName'],': ',item()?['Quantity']))

 

Please note I add a Dummy Compose action block after the Apply to ech and assign as its input the variable 'myOrderTextBlockArray'. The reason is, If you implement this logic, execute the flow and inspect 'Compose 3' output you will see the content of this variable:

[
  {
    "type": "TextBlock",
    "wrap": true,
    "size": "Medium",
    "text": "Product1: 3 units"
  },
  {
    "type": "TextBlock",
    "wrap": true,
    "size": "Medium",
    "text": "Product4: 2 units"
  }
]

 

And we just need to add 'myOrderTextBlockArray' variable to the Adaptive Card JSON. I just implemented this dummy Adaptive Card

 

Flow_iterateTextBlock_3.png

 

If you need further assigtance pleas let us know

 

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

oh wow. Much appreciation for diving into this, @efialttes . I didn't think it would be so involved. 

 

I'll have to get into it tomorrow morning but I appreciate your hard work and will follow up with a reply

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (1,930)