Hi Everyone,
I have a custom web resource on Account form showing Google Map location from Address1 field. When the form is exposed to CRM Portals the map stops showing the location.
Initially what I found is that script was breaking as Xrm.Page (Xrm context thing is not available in CRM Portals) so I added javascript code to get address1_composite field value like below:-
if(window.parent.Xrm!=null && window.parent.Xrm.Page!=null)
{
//get value from CRM form field
address= window.parent.Xrm.Page.data.entity.attributes.get('address1_composite').getValue();
}
else
{
//Get value from crm portals field
address=document.getElementById("address1_composite").value;
}
But still it's breaking like below

The reason is Server controls is not rendered but Script tries to get value from it. To solve this I tried adding the function call in document.ready also but it does not seem to work. Here is the complete script (code of web resource):-
<html><head>
<script src="maps.googleapis.com/.../js"></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
//Default location = Australia in case location is not found
var map_options = {
center: new google.maps.LatLng(-26.4420246,133.281323),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
var geocoder = new google.maps.Geocoder();
var address;
if(window.parent.Xrm!=null && window.parent.Xrm.Page!=null)
{
address= window.parent.Xrm.Page.data.entity.attributes.get('address1_composite').getValue();
}
else
{
address=document.getElementById("address1_composite").value;
}
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(14);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
//alert("Geocode was not successful for the following reason: " + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<meta></head>
<body style='word-wrap: break-word;'>
<div style='width: 100%; height: 100%;' id='map_canvas'></div>
</body></html>
In CRM Form it works ok:-

In Portals it does not mark/indicate the location:-
