Dynamic image in Report Template

363
8
Jump to solution
06-14-2021 09:47 AM
CarlosSousaFerreira
New Contributor III

I'm trying to include a dynamic image content in my report template using the value of one field to construct the image URL.

It says in the documentation of the Report template that this could be achieved through the $image keyword.

I've tried including a text like this in my template:

${$image | src:"https://anyserver.com/dynamicpage.ashx?data=${my_field}"}

But, when I try to load the template to the survey in survey123.arcgis.com, it raises an error:
Erro: An error occurred when checking the report template. The tag beginning with "${$image |" is unclosed. The tag beginning with "}"" is unopened.

I guess it is not liking the field data I'm trying to add to the image URL, but how can I do this?

Tags (2)
0 Kudos
2 Solutions

Accepted Solutions
Jim-Moore
Esri Regular Contributor

Hi @CarlosSousaFerreira while variable substitution in the src string isn't supported in the way you've demonstrated above (i.e. for substituting part of the URL string), you can use the value from a question as the complete URL. If your survey is published from Survey123 Connect, one option would be to construct the full URL in a hidden text question in your survey, then use this as the image source. For example, if you concatenate https://anyserver.com/dynamicpage.ashx?data=  and ${my_field} in a hidden text question named image_url, your report template syntax could then look like: 

${$image | src:image_url}

Hope this helps. Best, Jim

View solution in original post

ZhifangWang
Esri Regular Contributor

Hi @CarlosSousaFerreira ,

As we rolled out a security update late last week, it includes the fix to this "question mark in the image src" issue. It should work as expected now on the Survey123 website.

 

If you still observe any issues, please let us know.

 

View solution in original post

8 Replies
Jim-Moore
Esri Regular Contributor

Hi @CarlosSousaFerreira while variable substitution in the src string isn't supported in the way you've demonstrated above (i.e. for substituting part of the URL string), you can use the value from a question as the complete URL. If your survey is published from Survey123 Connect, one option would be to construct the full URL in a hidden text question in your survey, then use this as the image source. For example, if you concatenate https://anyserver.com/dynamicpage.ashx?data=  and ${my_field} in a hidden text question named image_url, your report template syntax could then look like: 

${$image | src:image_url}

Hope this helps. Best, Jim

View solution in original post

CarlosSousaFerreira
New Contributor III

Thanks! This work like a charm!
However, it makes me create a new field for the image_url value. Is there any way to avoid this?

0 Kudos
Jim-Moore
Esri Regular Contributor

Hi @CarlosSousaFerreira  following discussion with colleagues, it turns out it is possible to concatenate strings in an expression in the report template itself, using the plus symbol (+). So your report template syntax could look something like:

${$image | src:"https://anyserver.com/dynamicpage.ashx?data=" + my_field}

Note that this method is not documented; we're still assessing the best way to implement this syntax, but this should hopefully be useful for now.

Also note that when calling a question value within an expression, you drop the ${} syntax from the question name. So in this case ${my_field} is entered as my_field when inside the ${$image} expression.

Best, Jim

CarlosSousaFerreira
New Contributor III

Hi @Jim-Moore. Thank you so much for your help. That configuration works and it adds the value of my_field to the url, but it automatically removes the question mark (?), so it drives the url invalid. I've tried to substitute the question mark with ? and it doesn't remove it, but it still gives me an error when printig the report, even though the generated url is valid:

CarlosSousaFerreira_0-1624013432662.png

 



0 Kudos
Jim-Moore
Esri Regular Contributor

Hi @CarlosSousaFerreira thanks for raising this. On further discussion with colleagues, this is a known issue: a question mark (?) in an image source URL in the template will cause a print error. We're working on resolving this issue for the next release. Perhaps surprisingly, the issue does not occur if the question mark is in the answer to a question, so in the meantime, the workaround is to use the method described above, i.e. concatenate the URL in a separate text question and then use the question name as the image source. We'll endeavour to update this post with any developments. The fix should hopefully be included in our next beta website update on EAC as well. Best, Jim

CarlosSousaFerreira
New Contributor III

OK. Thanks! Hoping to see the fix for this in the next version. Take care, Carlos

0 Kudos
ZhifangWang
Esri Regular Contributor

Hi @CarlosSousaFerreira ,

As we rolled out a security update late last week, it includes the fix to this "question mark in the image src" issue. It should work as expected now on the Survey123 website.

 

If you still observe any issues, please let us know.

 

View solution in original post

CarlosSousaFerreira
New Contributor III

Hi @ZhifangWang ,

Just tested and it now works using the format proposed by Jim-Moore: ${$image | src:"https://anyserver.com/dynamicpage.ashx?data=" + my_field}! This is great!

Many thanks!

Best regards,

Carlos

0 Kudos