When designing functionality that queries runtime information of Processes, it is normally done through Process Entities.
Each process entity makes available part of the whole process runtime information stored by the OutSystems Platform. As such, if the number of executing process instances grows to millions of records, queries over process entities will be slow.
In this case, we recommend that you do the following:
Create an Entity to manually store runtime information you need about the process. This entity should be called<ProcessName>Process;
Use aProcess Callback Action or anActivity Callback Action to add logic to manually store the needed runtime information.
By creating this entity, you may also extend the logic and store other runtime information you need.
As an example, imagine a process to pay invoices of suppliers: the invoice has to pass a first level of approval, then a possible second level of approval (depending on the amount to pay), and, if rejected on any approval, an e-mail is sent to notify the supplier.
There is a requirement to make a report with the time it takes to make the first approval and also the possible second approval. There are thousands of invoices to pay, therefore, we should not use the process entity.
Let's disable the process entity...
...and create an InvoiceProcess entity to store the date and time of: invoice creation, first approval, and second approval.
Now, use the callback actions to fill the new entity with values for their attributes:
Add aOn Process Start callback action to the process to create a InvoiceProcess record with the invoice identifier and its creation date and time;
On the Level1Approval human activity, add aOn Close call back action to update the InvoiceProcess record with the first approval date and time;
On the Level2Approval human activity, add aOn Close call back action to update the InvoiceProcess record with the second approval sdate and time.
Overview of Best Practices for Designing Processes | Overview of Designing Processes