
Using CRM REST BUILDER i am successfully able to get the web api but the function is not returnning anything.I want to call getnotesImagesCallback(resultSet) function.Here is my code.Every effort will be appriciated.
<html>
<head>
<script src="../../ClientGlobalContext.js.aspx"></script>
<script src="new_/Script/SDK.REST.js" type="text/javascript"></script>
<title>Show Child Accounts</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="ecn.dev.virtualearth.net/.../mapcontrol.ashx" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var messageBox = null;
var lat = null;
var lon = null;
var City = null;
var AccountName = null;
var pushpin = null;
var pushpinCollection = new Microsoft.Maps.EntityCollection();
var messageBoxCollection = new Microsoft.Maps.EntityCollection();
/* document.onreadystatechange = function ()*/
function loadingmap()
{
alert("inside loadingmap");
document.onreadystatechange = function (){
alert("inside function");
if(document.readyState == "complete")
{
//initialise map
getMap();
alert("after get map");
var resultSet = getChildAccounts();
if (resultSet !== null && resultSet.length > 0) {
getnotesImagesCallback(resultSet);
}
/*
//Get child account records
getChildAccounts(); */
}
}
}
function getChildAccounts() {
alert("inside getChildAccounts");
var req = new XMLHttpRequest();
alert(req);
req.open("GET", parent.Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts?$select=accountid,accountnumber,address1_city,address1_country,address1_latitude,address1_longitude&$expand=account_parent_account($select=accountid)&$count=true", 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=\"*\",odata.maxpagesize=1000");
req.onreadystatechange = function() {
if (this.readyState === 4) {
alert("inside first if");
req.onreadystatechange = null;
if (this.status === 200) {
alert("inside second if");
var results = JSON.parse(this.response);
var recordCount = results["@odata.count"];
for (var i = 0; i < results.value.length; i++) {
var accountid = results.value[i]["accountid"];
alert(accountid);
var accountnumber = results.value[i]["accountnumber"];
var address1_city = results.value[i]["address1_city"];
var address1_country = results.value[i]["address1_country"];
var address1_latitude = results.value[i]["address1_latitude"];
var address1_latitude_formatted = results.value[i]["address1_latitude@OData.Community.Display.V1.FormattedValue"];
var address1_longitude = results.value[i]["address1_longitude"];
var address1_longitude_formatted = results.value[i]["address1_longitude@OData.Community.Display.V1.FormattedValue"];
//Use @odata.nextLink to query resulting related records
var account_parent_account_NextLink = results.value[i]["account_parent_account@odata.nextLink"];
}
} else {
parent.Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
//callback method
function getnotesImagesCallback(resultSet)
{
alert("hello");
//initialise message box
messageBox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0),
{
visible: false
});
messageBoxCollection.push(messageBox);
//Show current account
lat = window.parent.Xrm.Page.getAttribute("address1_latitude")
.getValue();
alert(lat);
lon = window.parent.Xrm.Page.getAttribute("address1_longitude")
.getValue();
City = window.parent.Xrm.Page.getAttribute("address1_city")
.getValue();
alert(City);
AccountName = window.parent.Xrm.Page.getAttribute("name")
.getValue();
pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon));
pushpin.Description = AccountName + ", " + City;
//show message box on mouse move
Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', displaymessagebox);
//remove message box on mouse lost
Microsoft.Maps.Events.addHandler(pushpin, 'mouseout', hidemessagebox);
pushpinCollection.push(pushpin);
//add collection to map
map.entities.push(pushpinCollection);
map.entities.push(messageBoxCollection);
if(resultSet.length > 0)
{
TotalImages = resultSet.length;
for(i = 0; i < resultSet.length; i++)
{
lat = resultSet[i].Address1_Latitude;
lon = resultSet[i].Address1_Longitude;
City = resultSet[i].Address1_City;
AccountName = resultSet[i].Name;
pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon));
pushpin.Description = AccountName + ", " + City;
//show message box on move move
Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', displaymessagebox);
//remove message box on mouse lost
Microsoft.Maps.Events.addHandler(pushpin, 'mouseout', hidemessagebox);
pushpinCollection.push(pushpin);
}
//add collection to map
map.entities.push(pushpinCollection);
map.entities.push(messageBoxCollection);
}
}
function displaymessagebox(e)
{
messageBox.setOptions(
{
description: e.target.Description,
visible: true,
offset: new Microsoft.Maps.Point(0, 25)
});
messageBox.setLocation(e.target.getLocation());
}
function hidemessagebox(e)
{
messageBox.setOptions(
{
visible: false
});
}
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('bingMaps'),
{
credentials: 'Aq3qdVTUDrWUuklMkomP_2gZqCyzrw_E9vgnD7cOwuGmcvyV2qI2BCIMr_1W8fxP',
center: new Microsoft.Maps.Location(41.956690, -103.137798),
mapTypeId: Microsoft.Maps.MapTypeId.road,
zoom: 10
});
}
</script>
<script type='text/javascript' src='www.bing.com/.../mapcontrol;callback=loadingmap' async defer></script>
</head>
<body >
<div id="bingMaps" style="width: 600px; height: 500px; position: relative;"></div>
</body>
</html>
*This post is locked for comments
I have the same question (0)Hello,
<html>
<head>
<script src="../../ClientGlobalContext.js.aspx"></script>
<script src="new_/Script/SDK.REST.js" type="text/javascript"></script>
<title>Show Child Accounts</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="ecn.dev.virtualearth.net/.../mapcontrol.ashx" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var messageBox = null;
var lat = null;
var lon = null;
var City = null;
var AccountName = null;
var pushpin = null;
var pushpinCollection = new Microsoft.Maps.EntityCollection();
var messageBoxCollection = new Microsoft.Maps.EntityCollection();
/* document.onreadystatechange = function ()*/
function loadingmap() {
alert("inside loadingmap");
document.onreadystatechange = function () {
alert("inside function");
if (document.readyState == "complete") {
//initialise map
getMap();
alert("after get map");
var resultSet = getChildAccounts();
if (resultSet !== null && resultSet.length > 0) {
getnotesImagesCallback(resultSet);
}
/*
//Get child account records
getChildAccounts(); */
}
}
}
function getChildAccounts() {
alert("inside getChildAccounts");
var results = null;
var req = new XMLHttpRequest();
alert(req);
req.open("GET", parent.Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts?$select=accountid,accountnumber,address1_city,address1_country,address1_latitude,address1_longitude&$expand=account_parent_account($select=accountid)&$count=true", false);
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=\"*\",odata.maxpagesize=1000");
req.onreadystatechange = function () {
if (this.readyState === 4) {
alert("inside first if");
req.onreadystatechange = null;
if (this.status === 200) {
alert("inside second if");
results = JSON.parse(this.response);
// You need to do following activity in lodingmap() after you get the result
var recordCount = results["@odata.count"];
for (var i = 0; i < results.value.length; i++) {
var accountid = results.value[i]["accountid"];
alert(accountid);
var accountnumber = results.value[i]["accountnumber"];
var address1_city = results.value[i]["address1_city"];
var address1_country = results.value[i]["address1_country"];
var address1_latitude = results.value[i]["address1_latitude"];
var address1_latitude_formatted = results.value[i]["address1_latitude@OData.Community.Display.V1.FormattedValue"];
var address1_longitude = results.value[i]["address1_longitude"];
var address1_longitude_formatted = results.value[i]["address1_longitude@OData.Community.Display.V1.FormattedValue"];
//Use @odata.nextLink to query resulting related records
var account_parent_account_NextLink = results.value[i]["account_parent_account@odata.nextLink"];
}
return results; // return the result
} else {
parent.Xrm.Utility.alertDialog(this.statusText);
return results; // return the result
}
}
};
req.send();
return results; // return the result
}
//callback method
function getnotesImagesCallback(resultSet) {
alert("hello");
//initialise message box
messageBox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0),
{
visible: false
});
messageBoxCollection.push(messageBox);
//Show current account
lat = window.parent.Xrm.Page.getAttribute("address1_latitude")
.getValue();
alert(lat);
lon = window.parent.Xrm.Page.getAttribute("address1_longitude")
.getValue();
City = window.parent.Xrm.Page.getAttribute("address1_city")
.getValue();
alert(City);
AccountName = window.parent.Xrm.Page.getAttribute("name")
.getValue();
pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon));
pushpin.Description = AccountName + ", " + City;
//show message box on mouse move
Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', displaymessagebox);
//remove message box on mouse lost
Microsoft.Maps.Events.addHandler(pushpin, 'mouseout', hidemessagebox);
pushpinCollection.push(pushpin);
//add collection to map
map.entities.push(pushpinCollection);
map.entities.push(messageBoxCollection);
if (resultSet.length > 0) {
TotalImages = resultSet.length;
for (i = 0; i < resultSet.length; i++) {
lat = resultSet[i].Address1_Latitude;
lon = resultSet[i].Address1_Longitude;
City = resultSet[i].Address1_City;
AccountName = resultSet[i].Name;
pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon));
pushpin.Description = AccountName + ", " + City;
//show message box on move move
Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', displaymessagebox);
//remove message box on mouse lost
Microsoft.Maps.Events.addHandler(pushpin, 'mouseout', hidemessagebox);
pushpinCollection.push(pushpin);
}
//add collection to map
map.entities.push(pushpinCollection);
map.entities.push(messageBoxCollection);
}
}
function displaymessagebox(e) {
messageBox.setOptions(
{
description: e.target.Description,
visible: true,
offset: new Microsoft.Maps.Point(0, 25)
});
messageBox.setLocation(e.target.getLocation());
}
function hidemessagebox(e) {
messageBox.setOptions(
{
visible: false
});
}
function getMap() {
map = new Microsoft.Maps.Map(document.getElementById('bingMaps'),
{
credentials: 'Aq3qdVTUDrWUuklMkomP_2gZqCyzrw_E9vgnD7cOwuGmcvyV2qI2BCIMr_1W8fxP',
center: new Microsoft.Maps.Location(41.956690, -103.137798),
mapTypeId: Microsoft.Maps.MapTypeId.road,
zoom: 10
});
}
</script>
<script type='text/javascript' src='www.bing.com/.../mapcontrol;callback=loadingmap' async defer></script>
</head>
<body>
<div id="bingMaps" style='width: 600px; height: 500px; position: relative;'></div>
</body>
</html>