Skip to main content
Answer

Javascript executes correctly in JSFiddle but not in Acumatica

  • August 26, 2023
  • 5 replies
  • 156 views

darylbowman
Captain II
Forum|alt.badge.img+15

This question is an extension of this one.

I have changed the second script to be as follows:

<script>
var map;
async function initMap() {
const center = { lat: 40.75, lng: -77 };
const { Map } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
const { Geocoder } = await google.maps.importLibrary("geocoding");

/* the map */
map = new Map(document.getElementById("map"), {
zoom: 7.8,
center: center,
mapId: "DEMO_MAP_ID",
});

/* get addresses from Acumatica field */
/*var addressesToPlot = px_alls["cstAddressesToPlot"].getValue();*/
var addressesToPlot = "Robisonia, PA; Mechanicsburg, PA; Philadelphia, PA";
var addresses = addressesToPlot.split(';');

/* encode addresses as lat/lng */
const geocoder = new Geocoder();
for (var i=0; i<addresses.length; i++)
{
geocoder.geocode({ 'address': addresses[i] }, (results, status) => {
if (status == google.maps.GeocoderStatus.OK) {
const marker = new AdvancedMarkerElement({
map: map,
position: results[0].geometry.location,
title: addresses[i],
});
}
});
}
}
initMap();
</script>

The page loads the map correctly, but the markers are not plotted on the map. However, the same code runs just fine in JSFiddle: (try it)


Could someone with more experience in JavaScript explain why that is?

@zfebert56 

Best answer by Zoltan Febert

Can you see any errors in the JavaScript console?

5 replies

Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3
  • Jr Varsity I
  • Answer
  • August 28, 2023

Can you see any errors in the JavaScript console?


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • August 28, 2023

Can you see any errors in the JavaScript console?

This was a fantastic idea I had not thought of, since, as previously mentioned, I have very little experience with JavaScript.

I’m genuinely embarrassed to say that the problem was that I had previously disabled the geocoding API in the Google API Console 🙈


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • August 28, 2023

Thank you for sharing your solution with the community @darylbowman!


  • Freshman II
  • May 8, 2024

@darylbowman - any chance you can explain this piece? 

var addressesToPlot = px_alls["cstAddressesToPlot"].getValue();

Where is cstAddressesToPlot defined/coming from?


Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3

@bguzman43 That is the control ID on the screen.