Say, I want a part of JSON template to be included or excluded based on a condition and that part is a JSON object and not a simple string. Example:
<<IF(TRUE, '{"type": "text\ntext"}', '')>>
Currently, that would return a string with escaped text like
{\"type\": \"text\\ntext\"}
Note that above JSON is hand typing. So it might not have a valid format. Itโs just to give you an idea.
And current workaround is create multiple workflows with different JSON template files but it is only good for templates with one or two condition checks.
One suggestion is to include a JSON type in AppSheetโs column type list. Anything printed from the JSON type will not be escaped (or stringify).
Thanks.
Solved! Go to Solution.
Unless I am completely misunderstanding your initial post, in your JSON body you can do things like:
{some JSON code}
<<If: (some condition in your table data)>>
{only sometimes JSON code}
<<EndIf>>
<<If: (a different condition in your table data)>>
{only sometimes JSON code}
<<EndIf>>
{more JSON code}
You donโt have to use the IF() from within AppSheet. You could even have multiple different JSON templates inside one file depending on a certain value from your data.
My personal example (JSON sent to Discord):
Interesting challenge. You may want to consider putting your snippets into fields and/or columns in a data source, then, just refer to them by โnameโ, e.g.
<<IF(Contains([Name],"ALPHA"),[Pattern1],[Pattern2])>>
(pattern1 and pattern2 are two different JSON snippets, [Name] is just a field I am keying off of)
Hereโs a working example. Is this the kind of thing you were asking about? Or something else perhapsโฆ
If you use [Pattern1] in a body template like in
Say [Pattern1] is { x: 5, y: 6 }
All those snippets will be stringify like this
JSON.stringify({ x: 5, y: 6 })
And it will be printed out like
"{"x":5,"y":6}"
which is a string.
Unless I am completely misunderstanding your initial post, in your JSON body you can do things like:
{some JSON code}
<<If: (some condition in your table data)>>
{only sometimes JSON code}
<<EndIf>>
<<If: (a different condition in your table data)>>
{only sometimes JSON code}
<<EndIf>>
{more JSON code}
You donโt have to use the IF() from within AppSheet. You could even have multiple different JSON templates inside one file depending on a certain value from your data.
My personal example (JSON sent to Discord):
Thanks @Bahbus. That will work for my most use cases. But in some cases, I have a virtual columns with JSON snippets which is used by a cloud app via the AppSheet integration.
I also like to use the same snippets within the workflow template.
I could maintain the two set of JSON snippets but it could be an error-prone process.
I also created a feature request that will be from integration side. In cloud-service integrations, provide a way to response a POST request
User | Count |
---|---|
18 | |
9 | |
8 | |
5 | |
5 |