Try ERPNext Buy Support Partners Foundation

Can't access Custom field's Fieldname from Custom Script

I have a custom field with Fieldname map of type Geolocation as shown in the image attached.

Here is the custom script:

	onload(frm) {
	    //Reference for project map
	    var projectmap = frm.doc.map;
	    //Multi-dimension array to store project coordinates
	    var projectlatlngs = [];
	    //Loop through Project's land coordinates and draw a plot of it
	    $.each(frm.doc.land_coordinates, function(land_project_coordinates_index, land_project_coordinates){
	        projectlatlngs.push([land_project_coordinates.longitude, land_project_coordinates.latitude]);
	    })
	    
	   var projectpolyline = L.polyline(projectlatlngs, {color: 'indigo', opacity: 1, weight: 1, fill: 1, fillOpacity: 0.2, fillColor: 'indigo'}).addTo(map);
	   map.fitBounds(projectpolyline.getBounds());
	}
});```

And I get the following error:

Uncaught (in promise) ReferenceError: ***map is not defined***

    at onload (eval at setup (script_manager.js:160), <anonymous>:12:150)
    at a (script_manager.js:90)
    at script_manager.js:108

![Test%20X%20-%20Google%20Chrome%201_26_2021%2004_57_51%20PM|690x415](upload://fVfMPvibho6cd6K9Af6Ka6h7HEi.png)

I see this is used in project doctype, but you are referencing onload(frm) only, are you adding this on server side or using the custom script?

The code doesn’t appear well when I post it here. I’m using custom script. The full code is just fine,I tried it with different doctypes were the map is not a custom field. But for this one, map is custom field and I’m having an error that it’s not defined

var map = frm.get_field("map").map;