Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

GOOGLE MAPS ENTITY FORM MULTIPLE MARKERS

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

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: GOOGLE MAPS ENTITY FORM MULTIPLE MARKERS

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans