Hi all,
I'm trying to show account or contact entity image on portals but when I try to run I receive an error message :
Liquid error: Exception has been thrown by the target of an invocation.
But, if I try to show another entity image (e.g. products) I have success.
My entity permissions is running well and if I remove the entityimage attribute from fetch my query run and show data normally.
{% fetchxml contact_account_query %}
<fetch version="1.0" mapping="logical">
<entity name="contact">
<all-attributes />
<filter type="and">
<condition attribute="contactid" operator="eq" value="{{ user.id }}">
</condition>
</filter>
<link-entity name="account" from="accountid" to="parentcustomerid" visible="false" alias="ai">
<attribute name="name" />
<attribute name="entityimage" />
<attribute name="entityimage_url" />
</link-entity>
</entity>
</fetch>
{% endfetchxml %}
{% if contact_account_query.results.entities.size > 0 %}
{% for result in contact_account_query.results.entities %}
<br>Contact Name : {{result.fullname}}
<br>Account Name : {{result['ai.name']}}
<img data-entityimage="{{result['ai.entityimage'] | join: ',' }}" />
<script type="text/javascript">
function toBase64(str) {
if (!str) return null;
var uarr = new Uint8Array(str.split(',').map(function(x) {
return parseInt(x);
}));
return btoa(String.fromCharCode.apply(null, uarr));
}
// Find any entity images and convert the byte string to base64
window.addEventListener('load', function() {
document.querySelectorAll('img[data-entityimage]').forEach(function(img) {
var data = img.dataset && img.dataset.entityimage;
var base64data = data ? toBase64(data) : null;
if (base64data) {
img.src='data:image/jpeg;base64,' + base64data;
}
});
});
</script>
{% endfor %}
{% endif %}