Hello,
I am using below code on the account entity to load map, it does load the map on the account but it is always defaulted to some dummy location.
When i open the text editor on the web resource I get the error : VEMap is undefined. When i debug it through IE8.0 i see that the breakpoint is at line 96.
var map = new VEMap("map");
Any help please?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <title>Bing Maps REST with Jquery</title> <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script> <script type="text/javascript"> /************************************************************************** This Function is for getting an object Id from the CRM IMP: Pass record object-type code and unique identifier as parameter option is selected in the CRM. By doing this you will get the context obj ID from the CRM. Parse the URL to retrieve the GUID as in the below code. **************************************************************************/ var objId; function getParameters(values, unescapeValues) { var objArr; var parameters = new Array(); var vals = ('?' == values.charAt(0) ? values.substr(1) : values).split("&"); for (var i in vals) { var entityIdArr; objArr = vals[i].split("="); if (objArr[0] == 'id') { objId = objArr[1].substr(3, 36); } } } /************************************************************************** This Function is for constructing the JSON object and retrieve the result from the web service **************************************************************************/ var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; var context = Xrm.Page.context || GetGlobalContext(); var serverUrl = context.getServerUrl(); /************************************************************************** Constructing the JSON object and query **************************************************************************/ function loadMapfromCRM() { getParameters(location.search, true); if (objId != null) { retrieveAccountRecord(objId); } } function retrieveAccountRecord(Id) { var retrieveAccountReq = new XMLHttpRequest(); retrieveAccountReq.open("GET", ODATA_ENDPOINT + "/AccountSet(guid'" + Id + "')", true); retrieveAccountReq.setRequestHeader("Accept", "application/json"); retrieveAccountReq.setRequestHeader("Content-Type", "application/json; charset=utf-8"); retrieveAccountReq.onreadystatechange = function () { retrieveAccountReqCallBack(this); }; retrieveAccountReq.send(); } function retrieveAccountReqCallBack(retrieveAccountReq) { if (retrieveAccountReq.readyState == 4 /* complete */) { if (retrieveAccountReq.status == 200) { //Success var retrievedAccount = JSON.parse(retrieveAccountReq.responseText).d; address = retrievedAccount.Address1_City + "," + retrievedAccount.Address1_StateOrProvince; map.Find(null, address, null, null, 0, 1, false, false, false, false, function (shapeLayer, results, places, moreResults, error) { var place = places[0]; var pushpin = new VEPushpin('1', place.LatLong, //latitude, longitude 'you can place your icon resource url as you see in the webresource', retrievedAccount.Name, //Title address //Notes ); //For adding the pushpins map.AddPushpin(pushpin); //For setting the Zoom level map.SetCenterAndZoom(place.LatLong, 7); }); } else { errorHandler(retrieveAccountReq); alert("retrieveAccountReqCallBack function failure END"); } } } </script> </head> <body> <div id="map" style="; top:0px; left:0px; width:100%; height:100%;"/> </body> </html> <script type="text/javascript"> //Load the map var map = new VEMap("map"); map.SetCredentials("YOUR CREDENTIALS<KEY>"); map.LoadMap(); //Resize the map window.onresize = function (event) { map.Resize(document.body.clientHeight); }; window.onresize(null); loadMapfromCRM(); </script>
Haroon