Hi,
I need to use "$when," and I have tried a lot of different things, and the results are not as expected.
My goal is to attach $data to a FactSet, filter when certain conditions in an array, and then show the results in a Fact.
This is my JSON;
{
"id": "XXXXX",
"name": "XXXXX",
"autonumbering_sequence_name_prefix": "XXXXX",
"date_created": "2020-04-13T13:34:58.762211Z",
"date_modified": "2020-04-13T13:39:33.499692Z",
"created_by": {
"id": "XXXXX",
"email": "[email protected]",
"first_name": "XXXXX",
"last_name": "XXXXX",
"avatar": null
"tokens": [
{
"name": "Document.CreatedDate",
"value": "Apr 13, 2020"
},
{
"name": "Document.GrandTotal",
"value": "R$10.000"
}
}
This is what I need:
{
"type": "FactSet",
"facts": [
{
"title": "Value",
"value": "{value}"
}
],
"$data": "{tokens}",
"$when": "{name == 'Document.GrandTotal'}"
}
Could you guys help out to understand if this is a bug or how can I resolve this?
I also tried to use this example, and it didn't work for me.
Iterations and Conditions
All this gets even more interesting when we add iterations and conditions to the plate. Let us admit we have the following data returned from any API or database
{
"title": "My list of people:",
"count": 4,
"people": [{
"firstName": "Micky",
"lastName": "Mouse",
"age": 44
},
{
"firstName": "Donald",
"lastName": "Duck",
"age": 12
},
{
"firstName": "Harry",
"lastName": "Potter",
"age": 18
},
{
"firstName": "Matt",
"lastName": "Hidinger",
"age": "28"
}
]
}
Now we want to bind this onto the following JSON template:
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "{title}"
},
{
"type": "FactSet",
"facts": [
{
"$data": "{people}",
"$when": "{$index.age > 12}",
"title": "{$index.firstName} {$index.lastName}",
"value": "{$index.age}"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
Thank you very much.
@diegoeliassantos
Based on my debugging, the $when expression within iteration is not having the context of that particular iteration. So, the condition expression fails since the parser can't find the properties provided. Not sure this is something implemented intentionally OR changes to provide current iteration context to $when expression is yet to be implemented.
For your case, I would suggest to make use of the isVisible property at FactSet level as below.
{
type: "FactSet",
$data: "{created_by.tokens}",
isVisible: "{name == 'Document.GrandTotal'}",
facts: [
{
title: "{name}",
value: "{value}",
}
]
}
@BalajiR I fixed this not too long ago. Are you using 0.1.1-alpha.1?
@BalajiR I fixed this not too long ago. Are you using 0.1.1-alpha.1?
Yes @dclaux, I used the version 0.1.1-alpha.1. Hope this is the latest alpha version.
@diegoeliassantos
This use case should work.
I see few mistakes in your json payload, and this is the corrected form. Notice characters in bold.
{
"id": "XXXXX",
"name": "XXXXX",
"autonumbering_sequence_name_prefix": "XXXXX",
"date_created": "2020-04-13T13:34:58.762211Z",
"date_modified": "2020-04-13T13:39:33.499692Z",
"created_by": {
"id": "XXXXX",
"email": "[email protected]",
"first_name": "XXXXX",
"last_name": "XXXXX",
"avatar": null**,**
"tokens": [
{
"name": "Document.CreatedDate",
"value": "Apr 13, 2020"
},
{
"name": "Document.GrandTotal",
"value": "R$10.000"
}
**]**
**}**
}
Assuming this is a fragment from a valid AdaptiveCards, I think the below is what you wanted.
{
"type": "FactSet",
"facts": [
{
"title": "Value",
"value": "{value}"
}
],
"$data": "{**created_by.**tokens}",
"$when": "{name == 'Document.GrandTotal'}"
}
@jwoo-msft ,
It is not working for the same context reason which i mentioned in previous comment. (at least with the 0.1.1-alpha.1 version of templating lib)
We have acknowledged this issue report. Please continue to follow the issue for updates/progress/questions. @matthidinger / @dclaux / @rebeccaanne / @paulcam206 / @nesalang / @almedina-ms FYI.
@dclaux / @jwoo-msft is this something that is fixed in the newer Templating implementation that is in prerelease? Thanks
@BalajiR FYI that we are working on updated templating offerings for JS + .NET to start with that integrates with BotFramework's AEL.. We should have a preview for you we are hoping by 5/5. Pls stay tuned.
@dclaux / @jwoo-msft is this something that is fixed in the newer Templating implementation that is in prerelease? Thanks
it works in .Net preview.
I can repro this on the latest code, I'll need to fix.
This is addressed in this PR: https://github.com/microsoft/AdaptiveCards/pull/3508 (namely, this commit https://github.com/microsoft/AdaptiveCards/pull/3508/commits/51c3f941680232dd315126336d4cd6aa25ff1dcd)
Below are cleaned up and correctly formatted test payloads for reference/testing.
Data:
{
"id": "XXXXX",
"name": "XXXXX",
"autonumbering_sequence_name_prefix": "XXXXX",
"date_created": "2020-04-13T13:34:58.762211Z",
"date_modified": "2020-04-13T13:39:33.499692Z",
"created_by": {
"id": "XXXXX",
"email": "[email protected]",
"first_name": "XXXXX",
"last_name": "XXXXX",
"avatar": null,
"tokens": [
{
"name": "Document.CreatedDate",
"value": "Apr 13, 2020"
},
{
"name": "Document.GrandTotal",
"value": "R$10.000"
}
]
}
}
Card:
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"body": [
{
"type": "FactSet",
"facts": [
{
"title": "Value",
"value": "${value}"
}
],
"$data": "${created_by.tokens}",
"$when": "${name == 'Document.GrandTotal'}"
}
]
}
As rendered:
