TIL #1 - Adaptive Cards $when

Today I learned about the simple but powerful Adaptive Card conditional layout function $when while looking into the Adaptive Card schema for a SPFx Adaptive Card Extensions (ACE)  

To drop an entire element if a condition is met, use the $when property. If $when evaluates to false the element will not appear to the user.

My case was a simple one, I wanted to show a value, say a key metric with a different color based on a threshold.  For example, if a sales figure is over or under an amount I want to display the TextBlock with a different color.  In the example below, the card should render the opportunitySum value in red (attention) if <= 3,500,000 and in green (good) if it is > 3,500,000.

Using sample data where the opportunitySum is 7,899,930 the format of the rendered card is:

There are other ways to do this, this is just a sample of how the $when conditional can be used.

HTH

Tweet Post Update Email

My name is Pete Skelly. I write this blog. I am the VP of Technology at ThreeWill, LLC in Alpharetta, GA.

Tags:
adaptive cards spfx ACE Viva til
comments powered by Disqus