Script to delete record

Viewing 5 reply threads
  • Author
    Posts
  • January 14, 2019 at 7:29 PM #33429

    Hy 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

    Brendan
    Keymaster

    form.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

    Thank you!

    form.deleteRecord(records[index]);

    Perfect!

    October 24, 2020 at 2:45 AM #42387

    Brecht DHeere
    Participant

    Hi, 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 Moffatt
    Participant

    The currently selected record is generally record, so to delete it you just need to do form.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 DHeere
    Participant

    Thank You Sam!

Viewing 5 reply threads

You must be logged in to reply to this topic.