
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&$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)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.