Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Filling location field automacally by script
Tagged: filling, location field, map view
- This topic has 9 replies, 4 voices, and was last updated 3 years, 8 months ago by Daniel Leu.
-
AuthorPosts
-
March 7, 2021 at 8:19 AM #43708
EddyParticipantHi Folks!
QUESTION:
How can I force the location field to look automatically for the geocoordinates without opening it manually?
CASE
We need a to have an overview of our clients on map view. But it would be to much work to fill the location field manually. So, I have a little script, that fills the location field based on the data in the adress fields.
function FILLING_locationfield() { var ADR_street = record.getFieldValue('fld-a2…'); var ADR_postalcode = record.getFieldValue('fld-b7…'); var ADR_city = record.getFieldValue('fld-e6…'); var ADR_country = record.getFieldValue('fld-b9…'); var TARGETFIELD_locationfield_id = 'fld-01…'; var ADDRESSDATA_for_locationfield = ADR_street + ", " + ADR_postalcode + " " + ADR_city + ", " + ADR_country ; record.setFieldValue(TARGETFIELD_locationfield_id, ADDRESSDATA_for_locationfield); } function FILLING_locationfield();
The problem is: This is filling the location field properly with the adress data. But in order that the location field is getting the fitting geocoordinates, I have to click on each adressfield manually and then to click on the save button.
So: How can I force the location field to look automatically for the geocoordinates without opening it manually?
Thanks in advance for any help.
Stay healthy, EDDY
March 7, 2021 at 10:57 AM #43710
Daniel LeuParticipantI’ve never used the location field, so I’m not familiar with it.
But in your script, you are missing a
document.saveAllChanges();
after setting the location field. If you click onRefresh records list
, all records should be updated and the location saved.March 7, 2021 at 11:00 AM #43711
EddyParticipantHi Daniel,
thanks for your reply.
Unfortunatly that does not help.
Moreover, it’s vice versa. If you click on “Refresh records list”, all the geocoordinates are disappear…
Regards, Eddy
March 7, 2021 at 1:57 PM #43712
Sam MoffattParticipantTry something like this:
record.setFieldValue('fld-51db8bacdefd454e823d01d04bbcd4a0', JSON.parse(`{"altitude": "90.19272306014727", "heading": "-0", "lat": "37.412871", "lon": "-121.898133", "pitch": 0, "title": "Great Mall, 1249 Great Mall Dr, Milpitas, CA 95035, United States" }`));
I forget why I put it as a JSON payload, I think because I was moving towards having this powered by a lookup from a field in another table but never got there. Anyway that works for me to set the location field.
March 7, 2021 at 2:03 PM #43713
EddyParticipantHi Sam!
Thanks a lot.
But I am afraid, this is not really, what I need and search for.
Actually I need a way, that fills in the geocoordinates automatically according to the address-date I wrote in by my script.
Hope, now I express myself better. Sorry for any confusion.
Regards, EDDY
March 7, 2021 at 2:59 PM #43714
Sam MoffattParticipantI don’t think there is an API for what you’re after if you don’t already have the co-ordinates.
March 8, 2021 at 10:14 AM #43721
Gerhard HoffmannParticipantHi Eddy,
I’m using TabForms since 4 months and the script is a real game changer. I’m not an expert in script programming, but my son helped me a lot.
I had a similar problem and I want to fill in the address fields to the field location, but not only to one address, it should do the work to all addresses. See, we use a for-next-loop.// start
var adresse_lang_id = ‘fld-5840ffe2e4b04f01a150329d15498877’;
var maps24_id = ‘fld-ce41104cdbc2405eb2ad0f9be8baa35a’;
var progress = Progress.new();function ProcessRecords(records) {
for (index in records) {if (progress.cancelled) {
console.log(‘Cancelled operation’);
break;
}var aRec = records[index];
var x = aRec.getFieldValue(adresse_lang_id);
aRec.setFieldValue(maps24_id, x);progress.updateProgress(index);
}
}var records = form.getRecords();
progress.totalCount = records.length;
progress.currentCount = 1;
console.log(‘Begin’);// show the progress sheet
progress.show(‘Processing Records…’);ProcessRecords(records);
// dismiss the progress sheet when done.
progress.dismissProgress();// save your changes
form.saveAllChanges();console.log(‘End’);
// end
Regards,
Gerhard
March 8, 2021 at 2:50 PM #43728
Daniel LeuParticipantHi Gerhard,
You can use the
progress
feature for that, but this seems to be an overkill for such a simple task. Following script does the same thing:function setAddress() { const adresse_lang_id = 'fld-xxx'; const maps24_id = 'fld-xxx'; for (r of form.getRecords()){ let x = r.getFieldValue(adresse_lang_id); r.setFieldValue(maps24_id, x); } document.saveAllChanges(); } setAddress();
But I’m wondering if using a form script for this tasks is what you really want. Whenever you run the script, all your maps24 field are updated.
It might be better to use a field script for that.function setAddress() { const adresse_lang_id = 'fld-xxx'; const maps24_id = 'fld-xxx'; let x = record.getFieldValue(adresse_lang_id); record.setFieldValue(maps24_id, x); document.saveAllChanges(); } setAddress();
Now the target field is only updated when the
adresse_lang
field is changed.March 9, 2021 at 11:05 AM #43742
Gerhard HoffmannParticipantHi Daniel,
thanks a lot for your answer and the better solution.
Regards, Gerhard
March 9, 2021 at 12:52 PM #43749
Daniel LeuParticipant?
-
AuthorPosts
You must be logged in to reply to this topic.