web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Google Maps in CRM Portals

(0) ShareShare
ReportReport
Posted on by 480

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

2063.issue.png

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:-

map.PNG

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

portal-maps.PNG

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Dmytro Rutkovskyi Profile Picture
    1,835 on at

    Hi Rizwan,

    Portals using its own techniques to render forms from CRM. They don't use custom controls from CRM. To execute Javascript on the form, insert this script into "Custom JavaScript"  memo in the entity form definition in CRM.

    As well you can look into the preferred way to work with maps in Portals here: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/portals/add-geolocation

    In your screenshot you are using GoogleMaps API, so preferred way to customize entity form with your Javascript.

  • Rizwan Aarif Profile Picture
    480 on at

    Hi Dmytro,

    Entity form is using a CRM Form Section to display and it already has the map (web resource). Also, I can see the script from CRM being exposed to Portals. Do you suggest adding the same to Entity Form (Custom Script) section?

  • Verified answer
    Dmytro Rutkovskyi Profile Picture
    1,835 on at

    If everything on the page, then you just need more testing with your JavaScript. Probably this is incorrect context object when you run script inside a web resource. Like try to window.top.document.getElementById instead document.getElementById.
    You can try to debug this code with chrome developers tools (looks like you are on chrome :) ) Find web resource code in Sources and put the breakpoint to your code, where you request the control value. Hope it helps.

  • Rizwan Aarif Profile Picture
    480 on at

    Hi Dmytro,

    Thanks for your help so far. You solved my issue :)

    Changing to window.top.document.getElementById  helped me.

    Thanks Again Friend.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans