Using Make to Perform Cascade Deletes in Knack

If you have been building solutions for a while with Knack (or Airtable, or Tadabase etc) you may have come across times when you have wanted to delete a record from an Object (or table in other databases)? The problem is that when the record you want to delete also has records connected to it (Child Records) in another object. Knack will leave these records 'orphaned' - by which I mean not connected to any parent record and in many case should also be deleted.


It is possible to do this in Javascript but this would be beyond my JS skill level and, after all, there is a reason we all have chosen a NO CODE tool to build our solutions.


The good news is that Make (formerly Integromat) can do this for us with just a few steps to set it up...


The Sample Knack Database

This example is based on an test app I have called Process Manager in which users can create processes which have multiple Process Steps - what we are going to configure is the option to mark a Process for Deletion and then have Make delete it and any linked Process Steps. Here is an existing page which displays all our processes:


In the Processes Object, I have already added a Yes/No field called Mark for Deletion and I have also set the Table shown above to have the following Filter on its Source:



Note the use of the "is not Yes". In this way it will immediately hide records marked for deletion.


What I am going to do next is add an Action Link to the table to mark the record deleted and trigger Make to process the deletion - but first I need to prepare a Make Scenario.


Starting the Make Scenario

Ideally, I want this process to happen relatively instantly when a record is deleted so I am going to use the Action Link to trigger Make with an Email containing the record ID of the Process record I want to delete (along with the Process Steps). We start by creating a Scenario in Make with a Mailhook (an option of their Webhook module):


When this is set up, we are then able to get the email address to which we can send an email from the Action Link in Knack:


Setting Up the Action Link..

Now we have the email address, we can configure the action link as follows:


Notice that I have both marked the record for deletion and then the second action sends a message to the address provided by Make with the {RECORD ID} value in the Message. Make sure that this is the only value in the message.


Back to Make...

Now we have Knack sending the message, we can go about configuring the rest of the scenario. Start by adding a router with two paths and then configure the FIRST path with a Knack Search Records module:


and configure like this:


Notice the fact that I have used a Make Substring text function to strip off any extra text from the email's html - and from experience, I have found that there are 3 characters we don't want at the start and, as the record id is always 24 characters long I end at the 27th.


This module, when run, will find all of the Process Steps records attached to the Process marked for deletion - the next step is to delete them:


Lastly, we need to add a Delete a Record Knack module to the second path out of the router:


This uses the same value to find the Process record to delete (no Search is required as we already have the Record ID for the one we need to delete).


Tidying Up

There is one issue that may well arise with this scenario - and that it that if there are no Process Steps records associated with a particular Process, that the Delete Process Steps module will produce an error. I usually resolve this type of issue with a filter - which I will add between Search for Process Steps and Delete Process Steps:



Summary


So there we are, a simple Make (formerly Integromat) Scenario to implement cascade deletes in Knack (and note that the same process could be used with other databases without this feature natively like Airtable and Tadabase).


If you would like to find out more about Knack click here.


and


More about Make here.









155 views0 comments

Recent Posts

See All