Simple Button to Delete Record

Tagged: , ,

Viewing 2 reply threads
  • Author
    Posts
  • March 28, 2025 at 6:04 PM #51749

    grooveagent
    Participant

    Hello all,

    I’m just starting to learn how to use scripts in TapForms 5. I do have some knowledge of Javascript from a web programming perspective.

    I thought I’d start with something simple such as create a button that deletes a record. I created the button, and assigned the following script which gets the current record, and then attempts to delete it:

    function delete_record() {
    
    	// get current record
    	var thisRecord = record.getId();
    	// delete the record
    	form.deleteRecord(thisRecord);
    }
    
    delete_record();

    The console reports: “deleteRecord: TypeError: Argument does not match Objective-C Class, line:(null)”

    I’m sure I’m doing something really noob here such as combining a record function with a form function.

    Thanks in advance.

    March 28, 2025 at 6:48 PM #51750

    Brendan
    Keymaster

    You can just pass in record into the deleteRecord() function. The getId() function returns the string ID of the record, but the deleteRecord() function requires an actual record object.

    Don’t forget to call form.saveAllChanges() too.

    March 29, 2025 at 2:15 PM #51753

    grooveagent
    Participant

    Thanks Brendan,

    For anyone who is looking this up in a search, this is the working code:

    function delete_record() {
    
    	form.deleteRecord(record);
    	form.saveAllChanges();
    }
    
    delete_record();
    • This reply was modified 2 days, 23 hours ago by grooveagent.
Viewing 2 reply threads

You must be logged in to reply to this topic.