microsoft / microsoft/AdaptiveCards

[Bug]Error in AdaptiveCards Templating SDK: Cannot Read Properties of Undefined ('Expression')

Open
#9,078 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Renderers Bug
Dominant language
C#
Stars
2k
Forks
595
Avg merge
1d 19h
Merged PRs (30d)
1

Description

Target Platforms

Other

SDK Version

2.3.1

Application Name

adaptivecards-templating

Problem Description

I encountered an issue where properties in the JavaScript version of the AdaptiveCards Templating SDK are undefined.
How can I resolve this issue?issue-adaptive-cards-sdk.docx

Screenshots

Image

Image

Card JSON
// Define the Adaptive Card template
    const cardTemplate = {"type":"AdaptiveCard","version":"1.0",
        "body":[
            {"type":"TextBlock","text":"Hello ${name}!"},
            {"type":"TextBlock","text":"=if(age >= 18, 'You are an adult.', 'You are a minor.')"}]};
    // Define dynamic data (this could come from an API or user input)
    const dynamicData = {"$root":{"name":"John","age":25}};
Sample Code Language

JS

Sample Code
<title>Adaptive Card with Expressions</title>

Adaptive Card with Dynamic Expression

<script src="https://unpkg.com/adaptivecards@2.1.0/dist/adaptivecards.min.js"></script> <script src="https://unpkg.com/adaptivecards-templating/dist/adaptivecards-templating.min.js"></script> <script> // Define the Adaptive Card template const cardTemplate = {"type":"AdaptiveCard","version":"1.0", "body":[ {"type":"TextBlock","text":"Hello ${name}!"}, {"type":"TextBlock","text":"=if(age >= 18, 'You are an adult.', 'You are a minor.')"}]}; // Define dynamic data (this could come from an API or user input) const dynamicData = {"$root":{"name":"John","age":25}};
// Use adaptive-expressions to evaluate expressions in the template
const template = new AdaptiveCards.AdaptiveCard();
const card = new ACData.Template(cardTemplate);
// Expand the template with the dynamic data
const cardPayload = card.expand({ $root: dynamicData });
// Parse and render the adaptive card
template.parse(cardPayload);
document.getElementById("adaptiveCardDiv").appendChild(template.render());
</script>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the HTML sample with the adaptivecards and adaptivecards-templating CDN scripts, comparing the reported SDK version with the versions loaded in the page. Check how the AdaptiveCards.AdaptiveCard, ACData.Template, and card.expand calls handle the supplied $root data; done means the sample renders both expressions without the undefined Expression error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.