Survey banner
The Dataiku Community is moving to a new home! Some short term disruption starting next week: LEARN MORE

Using JSON to travers a list of values in a Message Card in an MS Teams Reporter of a Scenario

martyg
Level 2
Using JSON to travers a list of values in a Message Card in an MS Teams Reporter of a Scenario

I have a list of values that I created in a Python, called "breach_list".  It contains anywhere from 1 to 24 strings representing variables that have breached a threshold.  I've set up some steps in a Scenario, the final one being a "send message" step.  That step sends a message to an MS Teams page if a breach occurs (determined by if a check on the data fails).  I want to be able to display the elements of that breach list, but right now all I can do is display the entire list.  Here is what it looks like right now:

Dataiku Image.png

 

The JSON code in the MS Teams message is as follows:

{
    "@type": "MessageCard",
    "@context": "https://schema.org/extensions",
    "themeColor": "${if(outcome == 'SUCCESS', '29AF5D', '')}${if(outcome == 'FAILED', 'F44336', '')}${if(outcome == '', '28A9DD', '')}",
    "summary": "${scenarioName} run report",
    "sections": [
        {
            "text": "${if(outcome == 'SUCCESS', '✅', '')}${if(outcome == 'FAILED', '🔴', '')}${if(outcome == '', '🔔', '')} ${scenarioName}: **${outcome}**",
            "facts": [
                { "name": "Project", "value": "${scenarioProjectKey}" },
                { "name": "Triggered by", "value": "${triggerName}" },
                { "name": "Thresholds breached", "value": "${breach_list}"}
            ]
        }
    ],
    "potentialAction": [
        {
            "@type": "OpenUri",
            "name": "View Report",
            "targets": [
                { "os": "default", "uri": "INSERT URL HERE" }
            ]
        }
    ]
}

In the above code block, all I do is sent it ${breach_list}, but I'd really like to iterate through the elements of that list and print them each out on a separate line.  Something like this:

     Thresholds breached

                      Increase in Scorability Mismatch
                      EXP Percent Problem Cases 7 Days or Less
                      EXP Percent Problem Cases 20 to 40 Days

How do I do this in JSON and in the messages card?

Thanks!


Operating system used: Windows


Operating system used: Windows


Operating system used: Windows


Operating system used: Windows


Operating system used: Windows

                  

0 Kudos
2 Replies
AlexT
Dataiker

Hi @martyg ,

Have you tried converting the ${breach_list} to a string seperate by  \n\n as mentioned :
https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?...

breach_list = ["Element 1", "Element 2", "Element 3"]
breach_list = '\n\n'.join(breach_list)

 

Thanks,

 

0 Kudos
martyg
Level 2
Author

I used that idea and did it like this:

breach_list_string = ""

for item in breach_list:
    breach_list_string = breach_list_string + "  * " + item + "<br>"

Then, in the JSON portion of the MS Teams reporter I included it in the text section:

"text": "${scenarioName}: **${outcome}** <br><br> **Thresholds breached:** <br> ${breach_list_string}",

That seemed to do the trick!

0 Kudos