This tutorial will guide you through the process of creating human-readable IDs for databases and data views. These IDs can be ascending numbers, such as 1, 2, 3.
In this example, we assume that you want to write records to a database called General DB (in practice you will use your own database here). We will equip these records with human readable IDs.
- In your application, start by creating a database General DB for building purposes. It will later store the data collected in your intake module. Add the field Request ID and set its type as over Text.
- Create another database named Counter DB. This will store the most recent number that was assigned as an ID. Add the field current_number and set its type as Number.
- Then, build a module consisting of a Write to a Database action and a Result node only. In the Write to a Database action, connect to the Counter DB database and enter counter in the ID field and 1 in the current_number field. Run the module in, both, the Test and Live environments. This only creates one record in the database. You can delete this module after you have executed it.
- In the intake module used to create records, implement the following logic just before the Write to a Database action writing to the General DB database:
- Add a Read from a Database action to read from the Counter DB database. Enter counter in the ID field to retrieve the record from Counter DB.
- Add a Number value named Current Number and reference the current_number variable from the Read From a Database action in the NUMBER field.
- Create a Text Block value named Request ID. Reference Current Number.
- Below the Request ID value node, create a Number value named Next Number. In the NUMBER field, reference the Current Number node and type +1. This value node will update the Counter DB database to ensure that each matter has a unique number.
- Add a Write to a Database action connecting the Counter DB database. Enter counter in the ID field and reference the Next Number node in the current_number field to update the record.
- In the Write to a Database action writing to General DB, reference Request ID in the REQUEST ID field. This is the node that collects all relevant data and stores it in the General DB database.
- Add a Read from a Database action to read from the Counter DB database. Enter counter in the ID field to retrieve the record from Counter DB.
Your unique ID is now ready to be used for each record in the database.
Â