Sending javascript variables to outsystem variables but keep getting null

Sending javascript variables to outsystem variables but keep getting null

  

Hello,


I have looked through the forum post where it shows how to pass javascript variables to Outsystem variables. However, When I try to do it from within my Maphandler, I always get a 'cannot read property of null' error. I have attached my oml. Could someone take a look and see where i've gone wrong?


Thanks

Solution

Hello Amos,

You have some issues with your javascript code. The correct code is:


"
function(event){
    
    var latitude = document.getElementById('"+FoodLocations_Latitude.Id+"');
    var longitude = document.getElementById('"+FoodLocations_Longitude.Id+"');
    console.log('clicked');
    var map ="+GoogleMaps.Id+";  
    var lat = event.latLng.lat();
    var lng = event.latLng.lng();
    console.log(lat +' '+ lng); 
    if(latitude !=null && longitude != null){
        latitude.value = lat;
        longitude.value = lng;
    }
    
    var button = document.getElementById('"+AddMarkerButton.Id+"');
    button.click();

}
"

Cheers,
R

Solution

Rodrigo Coutinho wrote:   

Hello Amos,

You have some issues with your javascript code. The correct code is:


"
function(event){
    
    var latitude = document.getElementById('"+FoodLocations_Latitude.Id+"');
    var longitude = document.getElementById('"+FoodLocations_Longitude.Id+"');
    console.log('clicked');
    var map ="+GoogleMaps.Id+";  
    var lat = event.latLng.lat();
    var lng = event.latLng.lng();
    console.log(lat +' '+ lng); 
    if(latitude !=null && longitude != null){
        latitude.value = lat;
        longitude.value = lng;
    }
    
    var button = document.getElementById('"+AddMarkerButton.Id+"');
    button.click();

}
"

Cheers,
R