In this blog, i am going to discuss about “Image” type attribute/field display in Dynamics Portal. Here we have an Image for a Product, we will display this image on Dynamics Portal.
I am creating a Web Template with name Display_image_Product.
Put below code in Source.
// Get Product Id from URL and assign it in pid
{%
fetchxml
my_query
%}
<fetch
version="1.0"
mapping="logical">
<entity
name="product">
<attribute
name="name"
/>
<attribute
name="productid"
/>
<attribute
name="entityimage"
/>
<attribute
name="entityimage_url"
/>
<filter
type="and">
<condition
attribute="productid"
value="{{ pid
}}" uitype="product"
operator="eq"/>
</filter>
</entity>
</fetch>
{%
endfetchxml %}
{%
for
result
in
my_query.results.entities
%}
<img
data-entityimage="{{
result.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
%}
In above code it will get a Product Guid and will fetch its related image.
Did not work for me. Entity Image is empty
ReplyDeleteIt worked after clearing cache (/services/about)
ReplyDeleteThanks Rafiq.
ReplyDeletegood solution thanks
ReplyDeleteThis is a really authentic and informative blog. Share more posts like this.
ReplyDeleteOpenspan Online Training
Openstack Online Training
Openstack Online Course
Words will not be enough for me to appreciate Doctor Abolo of Abolospell@gmail.com who lives in Africa, for the successful spells he has been casting for me, I have never trusted any anybody, the way I trust him. This great dr was the one that saved my marriage. If you use him, I promise, you will trust him too. Any spell he cast for me is 100%. I see results the very same day. He also cured me from a deadly virus (HSV), a virus I have known as a medical, it doesn’t have a cure, he cured a patient I introduced to him to get pregnant after 15 years of marriage. He has active herbal remedies for diseases, infections and viruses. you can get him via; Email: Abolospell@gmail.com or you may decide to send him a msg on whatsapp here +27743411428. thanks doctor you are the best.
ReplyDeleteis anyone getting the below when tryin to access the entity image?
ReplyDeleteimg data-entityimage="Liquid error: Object of type 'Adxstudio.Xrm.Web.Mvc.Liquid.ImageDrop' cannot be converted to type 'System.Collections.IEnumerable'.
this no longer works because of an update by msft, it has become easier, you can get the url of the image for the portal out of the image object.
DeleteJust set the source attribute of your img element to: src="{{ result.entityimage.url }}"
Yes it just started 2 days ago.
ReplyDeleteHi Dear,
ReplyDeleteI really prefer your blog..! This blog are very useful for me and other. So I see it every day.
Check out For Microsoft Dynamics 365 at Xrelements.com Microsoft Dynamics 365 customer service Australia XR Elements provides expert Microsoft Dynamics 365 solutions for customer service in Australia. Elevate your customer service capabilities, optimize workflows, and drive customer satisfaction with our tailored customer service-focused Dynamics 365 solutions.
Visit Now - https://www.xrelements.com.au/dynamics-365/customer-service/
Thanks.
I must be doing something wrong, I've created the web template and added the relevant code, but nothing is shown next to the account name ( I am trying to get images to show next to logged in user's account). Do I need to add these images to portal management first?
ReplyDelete