public string GetScript(int mainId) { using (var newArcAgt = new ArchiveAgent()) { //Setting the Parameters var archiveColumns = new string[] { Keyid, Contactid, Name, Department, Namedepartment , StreetaddressLine1, StreetaddressLine2, StreetaddressLine3 , StreetaddressCounty, StreetaddressCity, StreetaddressZip , PostalAddressLine1, PostalAddressLine2, PostalAddressLine3 , PostalAddressCounty, PostalAddressCity, PostalAddressZip , Country }; //Parameter - restriction - Archive restrictions var archiveRest = GetArchiveRestrictionInfos(mainId); //Parameter - page - Page number, page 0 is the first page int page = 0; //Parameter - pageSize – Number of records displayed per page const int pageSize = 10; // Get a page of results for an archive list, explicitly specifying // the restrictions, orderby and chosen columns ArchiveListItem[] arcLstItm = null; var script = "function initializeMarkers() {\n"; var placedCompanies = new HashSet <int>(); // Because we only want to register a place once. do { arcLstItm = newArcAgt.GetArchiveListByColumns( Archive, archiveColumns, new ArchiveOrderByInfo[0], archiveRest, null, page++, pageSize); foreach (ArchiveListItem archiveRow in arcLstItm) { int contactId = CultureDataFormatter.ParseEncodedInt(archiveRow.ColumnData[Contactid].DisplayValue); if (!placedCompanies.Contains(contactId)) { placedCompanies.Add(contactId); string address = string.Empty; address = address.Add(archiveRow.ColumnData[StreetaddressLine1].DisplayValue, ", "); address = address.Add(archiveRow.ColumnData[StreetaddressLine2].DisplayValue, ", "); address = address.Add(archiveRow.ColumnData[StreetaddressLine3].DisplayValue, ", "); address = address.Add(archiveRow.ColumnData[StreetaddressZip].DisplayValue, ", "); address = address.Add(archiveRow.ColumnData[StreetaddressCity].DisplayValue, ", "); if (address.IsNullOrEmpty()) { address = address.Add(archiveRow.ColumnData[PostalAddressLine1].DisplayValue, ", "); address = address.Add(archiveRow.ColumnData[PostalAddressLine2].DisplayValue, ", "); address = address.Add(archiveRow.ColumnData[PostalAddressLine3].DisplayValue, ", "); address = address.Add(archiveRow.ColumnData[PostalAddressZip].DisplayValue, ", "); address = address.Add(archiveRow.ColumnData[PostalAddressCity].DisplayValue, ", "); } address = address.Add(archiveRow.ColumnData[Country].DisplayValue, ", "); string lat, lng; GoogleMaps.GeocodeAddress(address, out lat, out lng ); var tooltip = System.Web.HttpUtility.JavaScriptStringEncode(archiveRow.ColumnData[Namedepartment].DisplayValue); script += string.Format("AddMarker(map, '{0}', {1}, {2} );\n", tooltip, lat, lng); } } } while(arcLstItm.Length != 0); script += "}"; return(script); } }