{"id":1837,"date":"2015-11-22T18:54:15","date_gmt":"2015-11-22T18:54:15","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=1837"},"modified":"2015-11-30T10:24:42","modified_gmt":"2015-11-30T10:24:42","slug":"show-child-accounts-on-bing-maps-under-parent","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=1837","title":{"rendered":"Show child accounts on Bing Maps under Parent"},"content":{"rendered":"<p>In this post we are going to demonstrate how we can add multiple pushpins in Bing Maps based on the latitude and longitude. First we need to make sure <strong>address1_latitude<\/strong> and <strong>address1_longitude<\/strong> should be added under account form and should be \u00a0filled for all account records based on their address.<\/p>\n<p><strong>Requirement<\/strong>: Let\u2019s say we have requirement to show all the child accounts (sub accounts) as pushpins on map under parent account and show their name, city when user will hover on pushpin.<\/p>\n<p><strong>Solution<\/strong>: We can simply develop an html web resource where we can use Bing Maps AJAX control to show pushpins for child account based on the latitude or longitude values. We can implement this in three steps:<br \/>\n\u2022 <strong>Get Bing Maps API<\/strong><br \/>\n\u2022 <strong>Need to retrieve all child accounts for current account<\/strong><br \/>\n\u2022 <strong>Add pushpins to Bing Maps based on latitude and longitude returned from child accounts<\/strong><\/p>\n<p><strong>So Let\u2019s follow below steps<\/strong><\/p>\n<p>\u2022 To get Bing Maps key, you can follow instruction <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ff428642.aspx\">here<\/a> to get it.<br \/>\n\u2022\u00a0We can create a new solution or can do this customization in base solution, (If you are new to solution, please refer our earlier posts to create solution).<br \/>\n\u2022 Let&#8217;s first upload <strong>REST.SDK.js<\/strong> to your solution, we can use retrievemultiple method under this library to get child records and use below settings (<strong>Note<\/strong>: <em>you can get this file under SampleCode\\JS\\RESTEndpoint\\JavaScriptRESTAssociateDisassociate\\JavaScriptRESTAssociateDisassociate\\Scripts<\/em>) under your CRM SDK folder, if you don&#8217;t have CRM SDK download and extract it first.<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap1.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1839 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap1-300x60.png\" alt=\"Bingmap1\" width=\"300\" height=\"60\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap1-300x60.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap1.png 449w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><strong>Note<\/strong>: <em>We have\u00a0used <strong>him<\/strong> prefix in our publisher it could be <strong>new<\/strong> for you if you are not using\u00a0specific prefix.<\/em><br \/>\n\u2022 Create new HTML web resource and use below details.<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap2.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1840 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap2-300x83.png\" alt=\"Bingmap2\" width=\"300\" height=\"83\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap2-300x83.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap2.png 591w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u2022 Use below code for this html web resource<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;html&gt;\r\n\r\n&lt;head&gt;\r\n    &lt;script src=&quot;..\/..\/ClientGlobalContext.js.aspx&quot;&gt;&lt;\/script&gt;\r\n    &lt;script src=&quot;..\/Script\/SDK.REST.js&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt;\r\n    &lt;title&gt;Show Child Accounts&lt;\/title&gt;\r\n    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=utf-8&quot;&gt;\r\n    &lt;script src=&quot;http:\/\/ecn.dev.virtualearth.net\/mapcontrol\/mapcontrol.ashx?v=7.0&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt;\r\n    &lt;script type=&quot;text\/javascript&quot;&gt;\r\n        var map = null;\r\n        var messageBox = null;\r\n        var lat = null;\r\n        var lon = null;\r\n        var City = null;\r\n        var AccountName = null;\r\n        var pushpin = null;\r\n\r\n        var pushpinCollection = new Microsoft.Maps.EntityCollection();\r\n        var messageBoxCollection = new Microsoft.Maps.EntityCollection();\r\n\r\n        document.onreadystatechange = function() {\r\n            if (document.readyState == &quot;complete&quot;) {\r\n                \/\/initialise map\r\n                getMap();\r\n                \/\/Get child account records\r\n                getChildAccounts();\r\n            }\r\n        }\r\n\r\n        function getChildAccounts() {\r\n            \/\/retrieve current entity id\r\n            var parentaccountId = window.parent.Xrm.Page.data.entity.getId();\r\n            var entitySchemaName = &quot;Account&quot;;\r\n            \/\/get all child records based on parent customer id\r\n            var odataQuery = &quot;?$select=Name,Address1_City,Address1_Latitude,Address1_Longitude&amp;&quot; +\r\n                &quot;$filter=ParentAccountId\/Id eq guid'&quot; + parentaccountId + &quot;'&quot;;\r\n\r\n            if (typeof(SDK) != &quot;undefined&quot;) {\r\n                \/\/The retrieveAccountsCallBack function is passed through as the successCallBack.\r\n                SDK.REST.retrieveMultipleRecords(entitySchemaName, odataQuery, getnotesImagesCallback, function(error) {\r\n                    alert(error.message);\r\n                }, function() {});\r\n            } else {\r\n                alert(&quot;Not able to load REST.SDK library&quot;);\r\n            }\r\n\r\n        }\r\n        \/\/callback method\r\n        function getnotesImagesCallback(resultSet) {\r\n\r\n            \/\/initialise message box\r\n            messageBox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), {\r\n                visible: false\r\n            });\r\n            messageBoxCollection.push(messageBox);\r\n\r\n            \/\/Show current account\r\n            lat = window.parent.Xrm.Page.getAttribute(&quot;address1_latitude&quot;).getValue();\r\n            lon = window.parent.Xrm.Page.getAttribute(&quot;address1_longitude&quot;).getValue();\r\n            City = window.parent.Xrm.Page.getAttribute(&quot;address1_city&quot;).getValue();\r\n            AccountName = window.parent.Xrm.Page.getAttribute(&quot;name&quot;).getValue();\r\n\r\n            pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon));\r\n            pushpin.Description = AccountName + &quot;, &quot; + City;\r\n            \/\/show message box on mouse move\r\n            Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', displaymessagebox);\r\n            \/\/remove message box on mouse lost\r\n            Microsoft.Maps.Events.addHandler(pushpin, 'mouseout', hidemessagebox);\r\n            pushpinCollection.push(pushpin);\r\n\r\n            \/\/add collection to map\r\n            map.entities.push(pushpinCollection);\r\n            map.entities.push(messageBoxCollection);\r\n\r\n            if (resultSet.length &gt; 0) {\r\n                TotalImages = resultSet.length;\r\n                for (i = 0; i &lt; resultSet.length; i++) {\r\n                    lat = resultSet[i].Address1_Latitude;\r\n                    lon = resultSet[i].Address1_Longitude;\r\n                    City = resultSet[i].Address1_City;\r\n                    AccountName = resultSet[i].Name;\r\n\r\n                    pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon));\r\n                    pushpin.Description = AccountName + &quot;, &quot; + City;\r\n\r\n                    \/\/show message box on move move\r\n                    Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', displaymessagebox);\r\n                    \/\/remove message box on mouse lost\r\n                    Microsoft.Maps.Events.addHandler(pushpin, 'mouseout', hidemessagebox);\r\n                    pushpinCollection.push(pushpin);\r\n\r\n                }\r\n                \/\/add collection to map\r\n                map.entities.push(pushpinCollection);\r\n                map.entities.push(messageBoxCollection);\r\n            }\r\n\r\n        }\r\n\r\n        function displaymessagebox(e) {\r\n            messageBox.setOptions({\r\n                description: e.target.Description,\r\n                visible: true,\r\n                offset: new Microsoft.Maps.Point(0, 25)\r\n            });\r\n            messageBox.setLocation(e.target.getLocation());\r\n        }\r\n\r\n        function hidemessagebox(e) {\r\n            messageBox.setOptions({\r\n                visible: false\r\n            });\r\n        }\r\n\r\n        function getMap() {\r\n            map = new Microsoft.Maps.Map(document.getElementById('bingMaps'), {\r\n                credentials: 'Your BingMaps key',\r\n                center: new Microsoft.Maps.Location(41.956690, -103.137798),\r\n                mapTypeId: Microsoft.Maps.MapTypeId.road,\r\n                zoom: 10\r\n            });\r\n        }\r\n    &lt;\/script&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n    &lt;div id=&quot;bingMaps&quot; style=&quot;width: 600px; height: 500px; position: relative;&quot;&gt;&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u2022 Save and publish your web resource and place this web resource to account form by navigating Insert -&gt;Web Resource under form editor.<br \/>\n\u2022 Save and publish form and open any account record, if current account will have any child record it will show pushpins for child accounts otherwise it will just show current account record pushpin.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap3.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1841 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap3-300x142.png\" alt=\"Bingmap3\" width=\"300\" height=\"142\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap3-300x142.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/11\/Bingmap3.png 598w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Reference: BingMaps SDK<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we are going to demonstrate how we can add multiple pushpins in Bing Maps based on the latitude and longitude. First we need to make sure address1_latitude and address1_longitude should be added under account form and should be \u00a0filled for all account records based on their address. Requirement: Let\u2019s say we have requirement to show all the&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=1837\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25,5,6,7,8],"tags":[35,255,253,252,254],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1837"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1837"}],"version-history":[{"count":10,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1837\/revisions"}],"predecessor-version":[{"id":1882,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1837\/revisions\/1882"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}