My previous blog post about mapping in Microsoft Dynamics CRM displayed a simple map with the location of a CRM Account.
The following post shows how to plot multiple CRM Accounts on a Yahoo! map.

Again, I'm using AJAX, but this time we also call the CRM Web Service in order to retrieve multiple accounts (for this example, we're retrieving All Active Accounts).
The code then iterates around the CRM Accounts and plots a marker for the Account postcode.
All the code is placed within the "ISV" folder again.
The code:
<html>
<head>
<script type="text/javascript"
src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=***REPLACEWITHYOURID***">
</script>
<style type="text/css">
#map {
height: 550px;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
// RETRIEVE ACCOUNTS
function displayAccounts()
{
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
" <soap:Header>" +
" <CrmAuthenticationToken xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <AuthenticationType xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">0</AuthenticationType>" +
" <OrganizationName xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">MicrosoftCRM</OrganizationName>" +
" <CallerId xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">00000000-0000-0000-0000-000000000000</CallerId>" +
" </CrmAuthenticationToken>" +
" </soap:Header>" +
" <soap:Body>" +
" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
" <q1:EntityName>account</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>name</q1:Attribute>" +
" <q1:Attribute>accountid</q1:Attribute>" +
" <q1:Attribute>address1_city</q1:Attribute>" +
" <q1:Attribute>address1_postalcode</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:Criteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>statecode</q1:AttributeName>" +
" <q1:Operator>Equal</q1:Operator>" +
" <q1:Values>" +
" <q1:Value xsi:type=\"xsd:string\">Active</q1:Value>" +
" </q1:Values>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:Criteria>" +
" </query>" +
" </RetrieveMultiple>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
var entityNodes = resultXml.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
// CREATE A MAP
var map = new YMap(document.getElementById('map'));
map.addTypeControl();
map.addZoomLong();
map.addPanControl();
map.drawZoomAndCenter("United Kingdom", 12);
for (var i = 0; i < entityNodes.length; i++) {
var entityNode = entityNodes[i];
var cityNode = entityNode.selectSingleNode("q1:address1_city");
var postcodeNode = entityNode.selectSingleNode("q1:address1_postalcode");
var city = (cityNode == null) ? null : cityNode.text;
var postcode = (postcodeNode == null) ? null : postcodeNode.text;
var newMarker = new YMarker(postcode);
map.addOverlay(newMarker);
}
}
window.onload = displayAccounts;
</script>
</body>
</html>