Recursive routines provide options for business processes that need to repeat but don't have a set number of times to iterate. They can be used for approvals, returns of unknown numbers of records, or many undefined processes.
The goals for the article are:
- Know how to create a recursive routine
- Understand some of the Use Cases
- See how Runs function
Before working with recursive routines, always have a tab available with the option to stop the engine, just in case.
Creating and Using Recursive Routines
The simplest Recursive Routine is one that calls itself until a specified event (value is reached, or no more values are found). Inputs are configured the same way, and you use the same return node.
Here's an example.
This routine takes an input value (1), adds one to it, and if the value is less than 4 it calls itself, adds 1, checks for less than 4, etc.
While the above is an additive example, it's the most basic one. A more real world example is an API call that returns a set number of records, and if there are more records it returns a page token to get the next set.
In the case below, the routine calls a number of records until there are no. ore left to return.
The Get Child Records has a limit of 250 records. The Connector leading to Get Next Records checks to see if any records were returned. If there were records (meaning it hasn't gotten to the end yet), it recursively calls itself and keeps processing.
The Add Relationship Records and the Summarize Nodes add the new records to the existing records. and pass them along to the next recursive call, or out to the original call.
This is a very simple example that combines both the additive and Process examples.
The Create Calendar Entry Data node creates records in a form as each record is processed.
You can also see that the routine has a number of records to create, and each time the routine processes it adds one for a comparison check (on the connector from the Start node).
Never Drop Never Fail
One interesting way that Request uses Recursive Routines is in our Never Drop Never Fail process. See the following article for an overview of the philosophy - Never Drop Never Fail
The routine is included in your Kinops instance - Handler Failure Error Process
As long as the result of the task is not "Stop processing", the system will attempt to continue the tree. If it fails again, another task is created. This recursive situation depends on human intervention to stop processing.
In the Next Article
In the next article, we'll look at Basic Ruby Syntax.
Create a recursive Routine that operated for a certain number of times before stopping. It should perform a simple action like displaying a value or looking up a value.
Updated over 1 year ago