'Programming' Knack with Integromat (part 1)
In this series, I'm going to be looking at one of my favourite No-Code databases, Knack, and looking at how we can build business logic using the Integration / Automation tool Integromat.
What is Knack?
If you've read any of my earlier posts about Knack, you'l know that it a brilliant No-Code platform for building responsive web applications which support multiple types of user (with relevant security), allows you to build modern and attractive user interfaces with charts, maps, etc and even allows you to create public facing pages and customer portals.
Integromat to the rescue!
If you look at their website, Integromat describe their platform as the 'Glue of the Internet' (a bit like Zapier) and then go on to say 'Integromat is the most advanced online automation platform'.
The implication here is that Integromat is a tool with which you can integrate a multitude of Internet services (which it is) - but it goes much further than that. This is a fantastic tool for automating within apps as well as between apps. Put simply, I think Integromat is the most must-have tool on the web!
What We'll be Automating
I am basing these articles on a Knack app I've built specially for this purpose and is, I hope, representative of what I see people needing to do in the real world (but maybe simplified). The app's main function is to provide a tool to manage processes within your organisation - you create a process and then set up a series of steps which are then assigned to different team members to complete.
To make this into a tool to help you standardise your workflows, the app allows you to create Templates from which your new active processes are created. The templates include the ability to hold all the standard steps associated with a process and who they should be assigned to (in relationship to the Owner of that particular process, i.e. the Owner, Owner's Manager or a specific person). This is what a process template for a new customer project would look like in the live app:
The database consists of four objects in Knack (plus the Accounts object to hold Team Members):
As you can see, the database has Templates and Template Steps and then Processes (i.e. ones that are running) and Process Steps. When a user creates a new Process, they have to select a Template and the idea is that the system would then automatically create the Process Steps from the Template and assign them to the correct person.
Trigger when a user adds a new Process (into table Processes). This record is connected to the Template as well as the Owner of the Process and their Manager (if any).
Retrieve all the Template Steps records linked to the associated Template and loop through them.
For each Template Step create a new Process Step and assign to correct person based on the Assign to Type field in the template step - either the Owner, Manager or a person specified in the template step.
We may also choose to send an email to each person about the process steps assigned to them - but maybe we'll leave this till next time...
Setting Up Integromat
Integromat needs to be connected to your database (a specific connection to each Knack app is required) and this is done in the Scenario (a scenario is an Integromat process) builder in Integromat:
Click on New Scenario and then choose Knack as an app which you will use in the scenario:
Click continue and add a Knack Trigger to the scenario:
You'll then be prompted to select a Webhook (or create one) - click Add and then Add again in the Connection field where you will need the Application ID and API Key from the API and Code section in Knack:
Your completed 'Webhook' would then look like this:
So we now have a trigger which will fire this Integromat Scenario every time a new Process is added by a user.
Next, we need an additional Knack step to retrieve the actual new Process record:
Now, having retrieved the Process record we can request all the Template Steps from the Knack database associated with the Process Template used - to do this we use a Knack Search records step:
Note the Limit field above - this tells Integromat how many records it can retrieve at once (100 is probably enough unless you have processes with more than 100 steps!).
Now, this is the clever part - having retrieved all the Template Steps records from the database, Integromat will now process all the following steps for ALL of these records (i.e. it will loop though them). All we have to do now is create all the Process Steps for our new process based on each of these template steps.
There is one BUT here! Each of the process steps is to be assigned to someone - and that someone depends upon the Assign to Type set in the template step. What we need here is a way of deciding which type of assignee is relevant and then adding the record appropriately. To do this I am going to use a Router module with 3 branches with appropriate filters set:
Now, we've nearly finished our Scenario - we just need to create the three Create Record modules for each of the router branches:
For processes Assigned to Owner:
and for those assigned to Owner's Manager:
and those assigned to a specific individual:
Finally, this is what the overall Scenario looks like:
A Knack Tip
Because the Integromat process doesn't run instantly, I generally add a message on form submit something like this:
And here's the new process, complete with it's Steps:
I hope this article has proven to be useful - the aim is to show how powerful a combination Knack and Integromat are! Next time we'll refine our app a little further and start to think about what might be needed if the template steps are changed etc.
If you want to find out more about Knack click here.
or Integromat click here.