Problem with SNAPSHOT in Email Body HTML

I'm having lots of trouble getting valid HTML for a "Send an email" automation task's Email body property when I include the SNAPSHOT function. When I remove the SNAPSHOT line, the email sends and looks fine. When I include the SNAPSHOT line, depending on how I tweak the syntax I either receive an error saving the app or the app saves but the automation errors out when invoked.

Does anyone know how to get this to work?

I'm following the model from the AppSheet Help article SNAPSHOT, which says that it can be used with any deep link data type:

  • When adding SNAPSHOT() to an email body, you need to wrap it in an <img> tab. For example:
    <img src="<<SNAPSHOT(LINKOTOVIEW("ViewName"))>>">

Following that model, here's the baseline version of my line:

<img src="<<SNAPSHOT(LINKTOFILTEREDVIEW("Chart", ([List ID] = [_THISROW].[List ID])))>>">

Here are examples of the various validation errors and how I got past some of them:

  • If I don't include an </img> end tag, I get errors like the following when saving the app: Template could not be loaded due to exception: The 'img' start tag on line 26 position 2 does not match the end tag of 'body'. Line 40, position 5.
  • If I don't replace the <, >, and " characters with HTML entities (i.e., &lt;, &gt;, &quot;) within the src attribute's quote-enclosed URL value (i.e., src="..."), I get errors like the following when saving the app: Template could not be loaded due to exception: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 26, position 11.
  • Both of the above at least make some sense even if they're not covered in the AppSheet Help article's example. However, even if I do all the above I still end up with an error. The app saves but the automation results in an error like: Error encountered in step with name [Email list summary]: Error: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 22, position 11.
0 9 964
9 REPLIES 9

Hi,

1. I have tried an email with the below email body, it's working fine.
<img src="<<SNAPSHOT(LINKTOFILTEREDVIEW("Chart", ("Val1" = [_THISROW].[Column-1])))>>">

2. I have tried another email with below content in the email template and email attachment, it worked.
<<SNAPSHOT(LINKTOFILTEREDVIEW("Chart", ("Val1" = [_THISROW].[Column-1])))>>

3. When I tried the below HTML content in email body, it was not working.
<img src="&lt;&lt;SNAPSHOT(LINKTOFILTEREDVIEW(&quot;Chart&quot;, (&quot;Val1&quot; = [_THISROW].[Column-1])))&gt;&gt;">

In the above HTML, the expressions are given using the HTML entities (&lt;  &gt;  &quot; ). Since the HTML content does not have the expression format "<<>>", expression was not detected. Once the email delivered, the content <img src="<<SNAPSHOT(LINKTOFILTEREDVIEW("Chart", ("Val1" = [_THISROW].[Column-1])))>>"> is rendered in the email client. Since expression was not detected and resolved, the snapshot was not generated. And the src is not a valid image url, the UI was not displaying the snapshot image.

Please use the SNAPSHOT function in the way mentioned in the 1st point. 

Additional Examples:
for the HTML email body <p>&lt;&lt;[Column-1] = &quot;Val1&quot;&gt;&gt;</p>, the email delivered is <<[Column-1] = "Val1">>The expression was not detected and the email UI rendered the HTML entities as string.

for the HTML email body <p><<[Column-1] = "Val1">></p>, the email delivered is Y (the result of the expression).

Thanks for troubleshooting this issue. Unfortunately, I observe the opposite behavior of what you report. See the following simple test cases I just ran, and which don't even attempt to address the more complex use of SNAPSHOT or <img>:

Line in Email bodyOutcome

<p>List: <<[List]>></p>โ€ฉโ€ฉ

dbaum_1-1656678617263.png

 

Error upon saving app:

Template could not be loaded due to exception: Name cannot begin with the '<' character, hexadecimal value 0x3C. Line 5, position 11.

<p>List: &lt;&lt;[List]&gt;&gt;</p>โ€ฉโ€ฉ

dbaum_0-1656678574770.png

 

App saves without error. Automation triggers when expected. Email sends. Delivered email includes the expected substitution of "&lt;&lt;[List]&gt;&gt;" with the value of the [List] column.

1. <p>List: <<[List]>></p>โ€ฉโ€ฉ thrown error because the actual HTML shown in the image (<p>List: <<List]>></p>โ€ฉโ€ฉ) does not have a valid expression format (<<[List]>> is represented as <<List]>>). 
2. <p>List: &lt;&lt;[List]&gt;&gt;</p>โ€ฉโ€ฉ will substitute the HTML entities with the actual value <p>List: <<[List]>></p>. But, it will not consider the expression <<List>> and replace the values.

Sorry for that confusing oversight. I made a typographical error simply in recreating what I had done in order to produce the screenshot. I see the same error even when the initial bracket isn't missing. See the following screenshot showing an error when I try to save the app with <p>List: <<[List]>></p> in the Email Body.

dbaum_0-1656941398297.png

In contrast, with <p>List: &lt;&lt;[List]&gt;&gt;</p>โ€ฉโ€ฉ in the Email Body I can successfully save the app. Further, when the task is invoked via the app, the email that gets generated does not include the literal text "<<[List]>>" but rather interprets the line as an AppSheet expression and substitutes the value of the [List] column as desired. See the following screenshot showing no error when saving the app.

dbaum_1-1656942363519.png

See also the following screenshot of the email received, showing the value of the [List] column substituted for &lt;&lt;[List]&gt;&gt;.

dbaum_3-1656942876056.png

 

 

 

Hi @dbaum ,

Sorry, my understanding on the issue was not clear earlier. 

Question 1:

If I don't include an </img> end tag, I get errors like the following when saving the app: Template could not be loaded due to exception: The 'img' start tag on line 26 position 2 does not match the end tag of 'body'. Line 40, position 5.

Ans: The HTML content given in the Email Body is being validated. Appsheet expects either self-closing (<img />) or closed (
<img></img>) tags. HTML5 accepts img tag even without a closing tag, but currently Appsheet does not support it. We will add this in documentation.

Question 2:

If I don't replace the <>, and " characters with HTML entities (i.e., &lt;&gt;&quot;) within the src attribute's quote-enclosed URL value (i.e., src="..."), I get errors like the following when saving the app: Template could not be loaded due to exception: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 26, position 11.


Answer 2: Since the special characters in the expression is used as special characters by HTML, the error was thrown. It's standard to use HTML entities (&lt; &gt; etc.,) in such cases. We have covered this in this documentation (https://support.google.com/appsheet/answer/11575774?visit_id=637926066606549668-4003848418&p=use-htm...). But still, it's mentioned for the custom HTML email template file. We will also mention that it's applicable for Email Body too.

Question 3:
Both of the above at least make some sense even if they're not covered in the AppSheet Help article's example. However, even if I do all the above I still end up with an error. The app saves but the automation results in an error like: Error encountered in step with name [Email list summary]: Error: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 22, position 11.

Answer 3:

The SNAPSHOT expression return a HTML with an image tag inside an anchor tag. e.g <a href="deeplink"><img src="link_to_snapshot" /></a>.
Since the SNAPSHOT expression is used for the src attribute in the image tag, the src was replaced by a HTML which collapsed the existing HTML resulted to error. I think, you have followed the Notes section in this documentation (

https://support.google.com/appsheet/answer/10107421?hl=en)

The below HTML content would work.
<html>
<head>
</head>
<body>
"&lt;&lt;SNAPSHOT(LINKTOVIEW(&quot;Chart&quot;))&gt;&gt;"
</body>
</html>โ€‹

We will change the documentation.

Hope this answers all your questions. Thanks!

 

Eventhough I don't use Snapshot at all, can we have more control over the way it's shown inside our templates, similar to image and latlong columns?

Thanks a lot for figuring this out. It's now working for me.

In your HTML, the quotation marks at the beginning and end of the SNAPSHOT line are irrelevant--they just get reproduced literally in the email. All that's needed is the following--just like any other AppSheet expression in an HTML-structured Email Body:

<html>
<head>
</head>
<body>
&lt;&lt;SNAPSHOT(LINKTOFILTEREDVIEW(&quot;Chart&quot;, ([List ID] = [_THISROW].[List ID])))&gt;&gt;
</body>
</html>โ€‹

As you outline, there's definitely plenty of need for clarification and correction in the help articles. I think that's how this came to your attention; thanks, @lizlynch for following up on the feedback I submitted via the SNAPSHOT() - AppSheet Help article.

Idk about you but I find both findings to be quite weird.
As you may know I use just HTML templates, but I haven't had your problems.

&lt;&lt; and &gt;&gt; are really reliable on my side.

My suggestion @dbaum is that you should use an actual .html file instead of pasting the html code inside the editor, this will help you to troubleshoot way better.

On the other hand, the only problem I share with you is the usage of quotation inside an HTML tag, any other thing, including the &lt; and &gt; work great with no problem whatsoever.

@Phil, this seem to be related to the problem I mentioned you weeks ago and I never got the time to send you proper feedback

Thanks, as always, for the guidance. It also occurred to me that I may need to switch to using a separate file as an HTML template in order to work through this. I wonder whether there are simply errors in how AppSheet parses HTML directly in the app's property fields when saving the app, but those don't come into play when using a separate file as a template.

I try to avoid templates since they're a hassle to deal with when upgrading an app version. Maybe there are good techniques that can be shared in conjunction with the August office hours on app lifecycle management. Here's the problem I encounter. If you just use the editor's, say, Email Body property, the production version and a different in-development version can each exist and the development version replaces the production version when the app is upgraded. However, when using a template if you upgrade an app version you have to account for which template file each app version points to and where those templates are stored. That includes remembering to do something like, when upgrading an app version, repoint the production app version to the production template and also replace the contents of that template with the revised contents of the development template. Alternatively, you have to do something like create a new template file anytime you want to edit in development so that you're not editing the production version, and then manage where that template is stored since upon upgrading the production app version it will point to the template referenced by the development app version.

Top Labels in this Space