Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Using Tap Forms 5 › Script to delete record
- This topic has 5 replies, 4 voices, and was last updated 5 years ago by
Brecht DHeere.
-
AuthorPosts
-
January 14, 2019 at 7:29 PM #33429
Gianantonio FiannaccaParticipantHy i se in javascript Api this:
form.deleteRecord(someRecord);
Can you telo me a little ex?
There is also a form.selectRecord(someRecord)I dont understand what insert in someRecord
In a script loop i want delete single record
Thank
January 14, 2019 at 8:14 PM #33432
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.
January 14, 2019 at 8:27 PM #33434
Gianantonio FiannaccaParticipantThank you!
form.deleteRecord(records[index]);
Perfect!
October 24, 2020 at 2:45 AM #42387
Brecht DHeereParticipantHi, when I run this script all the records are deleted in that form. I only want to delete the selected record. How can I do that?
October 24, 2020 at 12:02 PM #42390
Sam MoffattParticipantThe currently selected record is generally
record, so to delete it you just need to doform.deleteRecord(record).There are some times this isn’t true, particularly when working with the script editor and link to form fields, but for simple documents it should always be true.
October 25, 2020 at 1:59 AM #42394
Brecht DHeereParticipantThank You Sam!
-
AuthorPosts
You must be logged in to reply to this topic.