locked
how to show all records location on map in crm 2013 RRS feed

  • Question

  • HI,

    I have "property" entity and its attribute are "longitude" and "latitude". I want to get longitude and latitude of all records and display location on map. Please tell me what steps should be followed. I have no idea how to do that.

    Wednesday, April 16, 2014 8:01 AM

Answers

  • If you will check SDK you will find all this in sample code, but it seems you are not checking SDK. use your function like below

    <head>
     <title>REST Endpoint Paging with JScript</title>
     <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
     <script src="Scripts/json2.js" type="text/javascript"></script>
      <script type="text/javascript">

    function getLong()

    {

     var req = new XMLHttpRequest();
        req.open('GET', encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/new_propertySet?$select=new_Longitude&$filter=new_PropertyStatus/Value eq 100000000"), true);
        req.setRequestHeader('Accept', 'application/json');
        req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(req.responseText).d;

                    var EMailAddress1 = result.results[0].new_Longitude;
                    alert(EMailAddress1);

                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }

    </script>

    //Rest of your html page code, if you have latest SDK check for

    SDK\SampleCode\JS\RESTEndpoint\JavaScriptRESTRetrieveMultiple\JavaScriptRESTRetrieveMultiple


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, April 17, 2014 8:06 AM
    Moderator

All replies

  • Hi Aamir,

    For that you need to develop a custom webresource it may be on html or you can use silverlight as well, where you can get all of your entity records and show them as pushpins, you can also use a solution in codeplex.

    HTH


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Wednesday, April 16, 2014 8:23 AM
    Moderator
  • Hi Mahender,

    here is my web resource I want to modify this script please help me out

    Entity:Property

    Fields:Longitude ,Latitude

    Now i want to retrieve all records of property and display location in this web resource. Please guide me

    <!DOCTYPE html>
    <html>
      <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <style type="text/css">
          html { height: 100% }
          body { height: 100%; margin: 0; padding: 0 }
          #map-canvas { height: 100% }
        </style>
        <script type="text/javascript"
          src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCxN9C59DkpHJBMjKes5DwNwSCUZ5Zajs4&sensor=false">
        </script>
    <script type="text/javascript">
          function initialize() {
            var mapOptions = {
              center: new google.maps.LatLng(30.37532, 69.34512),
              zoom: 8,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("map-canvas"),
                mapOptions);
    google.maps.event.addListener(map, "click", function (e) {
     //lat and lng is available in e object
        var lat = e.latLng.lat();
        var lng = e.latLng.lng();

    var htmlfield=document.getElementById("pv1").value=lng;
    var htmlfield1=document.getElementById("pv2").value=lat;
    //var money=parseFloat(htmlfield.value);
    var long=htmlfield.toString();
    var lat=htmlfield1.toString();
    window.parent.Xrm.Page.getAttribute('new_longitude').setValue(long);
    window.parent.Xrm.Page.getAttribute('new_latitude').setValue(lat);
    //var TextBox1 = document.frames.IFRAME_mapview.document.all.pv1.value;
    //var CRMvar=Xrm.Page.getAttribute("new_longitude").getValue();
    //CRMvar=TextBox1;
    // alert("htmlfield:"+htmlfield);
    //window.parent.Xrm.Page.data.entity.attributes.get("new_longitude").setValue(htmlfield)
    //window.parent.document.crmForm.all.new_longitude.DataValue=htmlfield;

    });

          }
          google.maps.event.addDomListener(window, 'load', initialize);
        </script>
          </head>
      <body>
    <div id="map"></div>
    <div>
    <input class="InputText3" type="text" id="pv1" />
    <input class="InputText4" type="text" id="pv2" />
    </div>
        <div id="map-canvas"/></div>

      </body>
    </html>

    Wednesday, April 16, 2014 8:31 AM
  • Did you check this link ?? it has step by step instruction, it should help you to implement your requirement.


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, April 16, 2014 8:39 AM
    Moderator
  • Hello Mahender,

    Can you add query in my code for retrieve and tell me how can i set values by looping in my code

    Wednesday, April 16, 2014 10:32 AM
  • Hi Mahender,

    You sent me a codeplex link but it shows only single record location. Is it possible by using this solution i can show multiple record location?

    Wednesday, April 16, 2014 11:46 AM
  • I hope it should have option to show multiple records if you will put in dashboard and If you will refer first link it is retrieve multiple record to show in map.

    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, April 17, 2014 1:53 AM
    Moderator
  • Hi Mahender,

    I want to get longitude from "new_property" entity. I wrote this script but it is not retrieving longitude. Kindly check my script and tell me what did I mistake in it?

    function GetEmail()
    {
    var req = new XMLHttpRequest();
    var serverURL="http://mozzotech:5555/RealEstate/xrmservices/2011/OrganizationData.svc/";
     var oDataUri = serverURL+new_propertySet?$select=new_Longitude&$filter=new_PropertyStatus/Value eq 100000000";
    req.open('GET', encodeURI(oDataUri), true);
     req.setRequestHeader('Accept', 'application/json');
     req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
     req.onreadystatechange = function () {
     if (this.readyState == 4) {
     req.onreadystatechange = null;
     if (this.status == 200)
     { var result = JSON.parse(req.responseText).d;
     var EMailAddress1 = result.new_Longitude; // change this field with new_email schema name
     alert(EMailAddress1); }
     else { alert(this.statusText); } } };
     req.send();
     }

    Thursday, April 17, 2014 5:12 AM
  • Hi,

    I wrote a script for retrieving record but result is undefined. Please guide me

    function GetEmail() {
     
        var req = new XMLHttpRequest();
        req.open('GET', encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/new_propertySet?$select=new_Longitude&$filter=new_PropertyStatus/Value eq 100000000"), true);
        req.setRequestHeader('Accept', 'application/json');
        req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(req.responseText).d;
                    var EMailAddress1 = result.new_Longitude;
                    alert(EMailAddress1);
                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }

    Thursday, April 17, 2014 5:40 AM
  • Hello,

    1. Make sure you are using correct schema name for entity and fields.

    2. Make sure you have json library attached to your form.

    3. Make sure you have UR12 installed because getClientUri() will only work ur12, if you have rollup before that use getserverurl

    try to debug your code if still there is issue.


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, April 17, 2014 5:58 AM
    Moderator
  • Hello,

    I modified my code but please tell me loop syntax is correct in javascript or not?

    function GetEmail() {
       // var account = Xrm.Page.getAttribute("parentaccountid").getValue();
        //if (account === null || account === undefined) return;

        var req = new XMLHttpRequest();
        req.open('GET', encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/new_propertySet?$select=new_Longitude&$filter=new_PropertyStatus/Value eq 100000000"), true);
        req.setRequestHeader('Accept', 'application/json');
        req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(req.responseText).d;
    for (int i=0;i<=result.count;i++)
    {
                    var EMailAddress1 = result[i].new_Longitude;
                    alert(EMailAddress1);
    }
                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }

    Thursday, April 17, 2014 6:05 AM
  • Debug the Script and paste the error message so that i can help you


    ms crm

    Thursday, April 17, 2014 6:10 AM
  • Hello Mahender,

    Here is an image of debugging mode. please tell me how can i get new_longitude from results object?

    Thursday, April 17, 2014 6:13 AM
  • Hello Reddy,

    Here is an image of debugging the script. Kindly tell me how can i retrieve new_longitude from results object

    Thursday, April 17, 2014 6:16 AM
  • Hi,

    Kindly tell me is it correct syntax for looping ?

    for(var i=0;i<=result.results.count;i++)
    {
                    var EMailAddress1 = result.results[i].new_Longitude;
                    alert(EMailAddress1);
    }

    Thursday, April 17, 2014 6:29 AM

  • Hello Aamir,

    Please don't create multiple threads for the same question.

    Yes it is a correct way to loop retrievemultiple result.



    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, April 17, 2014 7:43 AM
    Moderator
  • hello Mahender,

    Kindly tell me how can I pass value from javascript into html webresource?

    here is my javascript code:

    function getLong()

    {

     var req = new XMLHttpRequest();
        req.open('GET', encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/new_propertySet?$select=new_Longitude&$filter=new_PropertyStatus/Value eq 100000000"), true);
        req.setRequestHeader('Accept', 'application/json');
        req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(req.responseText).d;

                    var EMailAddress1 = result.results[0].new_Longitude;
                    alert(EMailAddress1);

                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }

    Here is my Html Web resource code:



    <!DOCTYPE html>
    <html>
      <head>
        <title>Navigation functions (heading)</title>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <meta charset="utf-8">
    <style type="text/css">
       .labels {
         color: red;
         background-color: white;
         font-family: "Lucida Grande", "Arial", sans-serif;
         font-size: 10px;
         font-weight: bold;
         text-align: center;
         width: 40px;     
         border: 2px solid black;
         white-space: nowrap;
       }
     </style>

        <style>
          html, body, #map-canvas {
            height: 100%;
            margin: 0px;
            padding: 0px
          }
          #panel {
            ;
            top: 5px;
            left: 50%;
            margin-left: -180px;
            z-index: 5;
            background-color: #fff;
            padding: 5px;
            border: 1px solid #999;
          }
        </style>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=geometry"></script>
        <script>
    var poly;
    var geodesicPoly;
    var marker1;
    var marker2;

    function initialize() {
      var mapOptions = {
        zoom: 4,
        center: new google.maps.LatLng(24.893379,67.028061)
      };

      var map = new google.maps.Map(document.getElementById('map-canvas'),
          mapOptions);

      map.controls[google.maps.ControlPosition.TOP_CENTER].push(
          document.getElementById('info'));


      marker1 = new google.maps.Marker({
        map: map,
        draggable: false,
    icon:'People.png',
        google.maps.LatLng(24.892937, 67.088348)
      });

      marker2 = new google.maps.Marker({
        map: map,
        draggable: false,
        google.maps.LatLng(24.899718, 67.072895)
      });
     marker3 = new google.maps.Marker({
        map: map,
        draggable: false,
    labelContent: "$425K",
       labelAnchor: new google.maps.Point(24.837584,67.080994),

        google.maps.LatLng(24.837584, 67.080994)
      });

      var bounds = new google.maps.LatLngBounds(marker1.getPosition(),marker2.getPosition());
      map.fitBounds(bounds);
    var bound = new google.maps.LatLngBounds(marker2.getPosition(),marker3.getPosition());
      map.fitBounds(bound);
      google.maps.event.addListener(marker1, 'position_changed', update);
      google.maps.event.addListener(marker2, 'position_changed', update);
    google.maps.event.addListener(marker3, 'position_changed', update);
      var polyOptions = {
        strokeColor: '#FF0000',
        strokeOpacity: 1.0,
        strokeWeight: 3,
        map: map,
      };
      poly = new google.maps.Polygon(polyOptions);

      var geodesicOptions = {
        strokeColor: '#CC0099',
        strokeOpacity: 1.0,
        strokeWeight: 3,
        geodesic: true,
        map: map
      };
      geodesicPoly = new google.maps.Polyline(geodesicOptions);

      update();
    }


    google.maps.event.addDomListener(window, 'load', initialize);

        </script>
      </head>
      <body>
        <div id="map-canvas"></div>
      </body>
    </html>

    Thursday, April 17, 2014 7:49 AM
  • If you will check SDK you will find all this in sample code, but it seems you are not checking SDK. use your function like below

    <head>
     <title>REST Endpoint Paging with JScript</title>
     <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
     <script src="Scripts/json2.js" type="text/javascript"></script>
      <script type="text/javascript">

    function getLong()

    {

     var req = new XMLHttpRequest();
        req.open('GET', encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/new_propertySet?$select=new_Longitude&$filter=new_PropertyStatus/Value eq 100000000"), true);
        req.setRequestHeader('Accept', 'application/json');
        req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(req.responseText).d;

                    var EMailAddress1 = result.results[0].new_Longitude;
                    alert(EMailAddress1);

                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }

    </script>

    //Rest of your html page code, if you have latest SDK check for

    SDK\SampleCode\JS\RESTEndpoint\JavaScriptRESTRetrieveMultiple\JavaScriptRESTRetrieveMultiple


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, April 17, 2014 8:06 AM
    Moderator