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 ENTITY FORM MULTIPLE MARKERS

(0) ShareShare
ReportReport
Posted on by 100

Hello,

Thank you for reading this. I have owners of accounts(sales reps). every owner has about 80-90 accounts and I want to display these addresses on google maps as red markers. I have used google maps in the past and currently display it on a form but does not have multiple markers. Also, I have created a form for this and based on the owner field on the new form, I want to search for all the accounts for every owner and want to display it. I have created a webpage html web resource but don't understand how I will get the data from another entity into this entity and iterate through it and display it on the marker. Please have a look at my code below.

Thank you!

<html><head>
<script src="maps.googleapis.com/.../js;amp;sensor=false"></script>
<script>
function initialize()
{
var Salesrep = Xrm.Page.data.entity.attributes.get("ownerid").getValue()[0].id.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_accountfuels?$select=new_fulladdress,new_dba&amp;$filter=_ownerid_value eq " + Salesrep, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function ()
{
if (this.readyState === 4)
{
req.onreadystatechange = null;
if (this.status === 200)
{
var results = JSON.parse(this.response);
var locations;
for (var i = 0; i<=results.value.length; i++)
{
var new_fulladdress = results.value[i]["new_fulladdress"];
var new_name = results.value[i]["new_dba"];
var map_canvas = document.getElementById('map_canvas');
var map_options = {center: new google.maps.LatLng(41.8336479, -87.872046), zoom: 10, mapTypeId: google.maps.MapTypeId.ROADMAP }
var map = new google.maps.Map(map_canvas, map_options)
var geocoder = new google.maps.Geocoder();
var address = window.parent.Xrm.Page.data.entity.attributes.get('new_fulladdress').getValue();
geocoder.geocode({'address': results.value[i]["new_fulladdress"] }, 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 });
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(results.value[i]["new_dba"]);
infowindow.open(map, marker);
}
})(marker, i))
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});

}

}
else
{
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();

}


google.maps.event.addDomListener(window, 'load', initialize);
</script>

<meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta charset="utf-8"><meta></head>
<body style="word-wrap: break-word;">

<br></body></html>


*This post is locked for comments

I have the same question (0)
  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    You can use CRM Rest builder tool to generate your code to retrieve the required account.

    This is the easiest way to build the query as well as execute it and see the results.

    carldesouza.com/dynamics-crm-rest-builder

    You can download the tool here- github.com/.../releases

    Hope this helps.

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