Search Results for 'form.getRecords'
Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Search › Search Results for 'form.getRecords'
-
AuthorSearch Results
-
January 17, 2019 at 12:39 AM #33476
In reply to: How do I get selected records from Javascript?
BrendanKeymasterHi Jose,
You can’t get the specific selected records if you’ve multi-selected some records. But you can loop through record in a form or a saved search and do something with those. And you can get the currently selected record (singular).
To get all the records in a form:
var records = form.getRecords();
To get all the records in the currently selected Saved Search:
var records = search.getRecords();
To get the current record just reference
record
.But I suppose it could be useful to be able to get an array of the currently selected records instead of just one.
January 14, 2019 at 8:14 PM #33432In reply to: Script to delete record
BrendanKeymasterform.selectRecord(someRecord)
is for telling Tap Forms to select a record. It’s useful when you use JavaScript to add a record to your form.For deleting a record, you need to get the record first before you can delete it.
If you want to delete a single record in a loop, you have to first get the records from the form. Then loop through them, check the record to see if it’s the right one to delete, then call the function to delete it.
var records = form.getRecords(); var field_id = 'fld-....'; for (var index = 0, count = records.length; index < count; index++){ var aRecord = records[index]; var field_value = aRecord.getFieldValue(field_id); if (field_value == 'some value') { form.deleteRecord(aRecord); } } form.saveAllChanges();
Something like the above should work but it has to be modified for your own form of course.
November 25, 2018 at 9:48 PM #32071In reply to: Mileage Tracker (Tap Forms 5.3)
Ryan MParticipantThought I’d play around and see if I could come up with a different approach to the same mileage tracker. This would probably be closer to a fuel log rather than a simple mileage tracker.
The inputs would be:
– odometer value
– Price per gallon
– Gallons filledA script would calculate your mileage since last fill up as well as your miles per gallon.
The script uses the default created date field to sort all records by their created date. This assumes that you’re entering in your mileage log around the time you filled up.
Here’s the script for those interested
var odometer_id = 'fld-9674e316bfed408ca6710ce81b72bf05'; var vehicle_id = 'fld-64b0b17a635f49b8b40867e45f8d24db'; var date_created_id = 'fld-2097149a2eeb4d4e892f13b62de6b5ea'; // sort records in ascending order by date value var dateSorter = (a, b) => a.getFieldValue(date_created_id) - b.getFieldValue(date_created_id) var run = () => { var vehicle = record.getFieldValue(vehicle_id); var odometer = record.getFieldValue(odometer_id); var records = form.getRecords() .filter(r => r.getFieldValue(vehicle_id) === vehicle) .sort(odometerSorter) var odometerValues = records.map(r => r.getFieldValue(odometer_id)); var currentRecordIndex = odometerValues.indexOf(odometer); var previousRecordIndex = currentRecordIndex === 0 ? 0 : currentRecordIndex - 1 var mileageValue = odometerValues[currentRecordIndex] - odometerValues[previousRecordIndex] return mileageValue; } run();
Attachments:
You must be logged in to view attached files.October 29, 2018 at 1:00 PM #31484In reply to: Double rating value in all entries
Andy RawlinsParticipantIn the script editor I selected the rating field and copied the ID into your script like this:
var rating_id = 'fld-0f294ce98c3043e0a9873bfe1933276e;;
var records = form.getRecords();
for (var index = 0, count = records.length; index < count; index++){
var aRecord = records[index];
var rating = aRecord.getFieldValue(rating_id);
aRecord.setFieldValue(rating_id, rating * 2);
}
form.saveAllChanges();I didn’t see anything happen at all. Looking at it now, I left off the single quotes, have some extra characters at the beginning and an extra semicolon at the end. All these things appear in the email version of the script but not here on the website. I guess Mail has garbled it a bit. I have some other databases to do so will try it on them :)
Many thanks
Andy
October 27, 2018 at 11:56 AM #31452In reply to: Double rating value in all entries
BrendanKeymasterHi Andy,
You could definitely write a Form Script to do this. Or you could also use the Advanced Find & Replace function to do this. I’d make a backup of your document first whatever you do though.
With the Find & Replace method you could start with searching the Rating field for 5, then set the value to 10. Then search for 4 and set the value to 8, then search for 3 and set it to 6, then 2 setting it to 4, then 1 setting it to 2.
You have to do it in reverse as described above because if you go the other way, you’ll end up changing values you already changed.
Or here’s a Form Script you can use for it:
var rating_id = 'fld-3baff54c8e164de9b9ad3f0fbb040bc6'; var records = form.getRecords(); for (var index = 0, count = records.length; index < count; index++){ var aRecord = records[index]; var rating = aRecord.getFieldValue(rating_id); aRecord.setFieldValue(rating_id, rating * 2); } form.saveAllChanges();
You need to use your own rating field ID though (e.g. ‘fld-…..’). The above is specifically for my test form.
But make sure you run it only 1 time otherwise you’ll double the rating values again.
October 7, 2018 at 11:32 PM #30952In reply to: Can't script a record update on iPad
BrendanKeymasterSure, you could update a record in a Field Script. An example of that might be selecting something from a Pick List that triggers a script to run and it updates a different field in that same record.
You could also have a Saved Search that fetches the records you want to update and run the script just on those records. You would use
search.getRecords()
instead ofform.getRecords()
. Or you can ask the form for a specific with a provided name. E.g.var search = form.getSearchNamed('Action & Adventure');
Then dosearch.getRecords();
. -
AuthorSearch Results