I have a suble script problem:
I want to create an artificial location field value.
I wrote this little script:
function SetCoordinates() {
// Durch eigenen Code ersetzen
var coord_id = 'fld-65d2a762b14542f9abbca1d521df2e37';
var title_id = 'fld-692eb15910f7433181f8f8a6b2fceccc';
var gps_lon_id = 'fld-4a453e4f44854f0f893d3e275d4342c4';
var gps_lat_id = 'fld-4dfd053afaec40b58395083e694085ac';
var location_value = record.getFieldValue(coord_id);
location_value["title"]= "GST " + record.getFieldValue(title_id);
location_value["lon"]=record.getFieldValue(gps_lon_id);
location_value["lat"]=record.getFieldValue(gps_lat_id);
record.setFieldValue(coord_id, location_value);
}
SetCoordinates();
If the field coord_id has already a value this works.
If it has no value (such es no one pressed the location icon before) this doesn’t work. How can I create an empty data structure of the type location?
Thanks for hints
The Location field value is just a dictionary. So you need to make a new dictionary object in JavaScript before you set the values on it. Essentially you’re getting a null value back from getFieldValue(). If you get a null value, then you just create an empty dictionary and then your code should work.
var location = {};