Tracing Business Rules
Overview
During the development stages of a project, or in the Production environment, there are situations where errors need to be traced or debugged.
Bizagi offers the possibility to trace errors in the Processes Workflows (to control and diagnose potential errors) so that administrators can determine if the business rules, validations, interface invocations, or the Process itself need to be modified.
This is a powerful functionality for Business Rules in particular, aiding in the understanding and detection of behaviors that require adjustment.
To enable the debug and trace feature, please refer to Error and Control Diagnostics.
Traces in Business Rules
For Business Rules, in addition to activating the corresponding trace options and levels, it is also necessary to include a trace command line in the Business Rule's code to define what exactly (the detail level) needs to be traced.
This command line will record customized information in a separate log (.txt) file, allowing users to trace specific details within the rule.
Traces are built using the trace function.
Important Notes
-
File Name: The .txt file name where traces will be stored.
Note: If the File Name contains a non-alphanumeric character (
#, ?, &, $, %, *
), Bizagi automatically replaces that character with an underscore (_) to prevent system errors.
Example: If your file name is c#test, the trace file will be named c_test_log.txt. -
Object to be traced: This identifies the trace object (attribute or variable) in the log file.
- The object can be an attribute (selected via a navigational XPath expression), a function, or a variable.
- The text in quotes can be any text; it does not need to match the attribute name in the data model.
You can find this function in the Tracing category.
Example
A Transportation and Logistics company has defined a process called Shipping Process to manage and monitor international shipments.
The first task in this process allows customers to calculate the cost of their shipments by providing the dimensions and weight of the package.
The estimated cost is calculated based on the volumetric weight, real weight, and the cost per pound, which varies by destination country.
Volumetric Weight Calculation
The volumetric weight reflects the density of a package.
A less compact item generally occupies more volume in comparison to its actual weight.
Bizagi determines the volumetric weight using a conversion factor (assumed to be 4000
), using the formula:
Length * Width * Height / 4000
To verify every step of the cost calculation, Business Rule traces can be configured.
Configuring Business Rule Traces
1. Create the Expression
- Define an expression associated with a button in the Form of the Quote Shipment Task.
- Add the Button and associate an Action.
2. Include the Business Rule Code
- Obtain the Cost per Pound from the RateTable Entity based on the destination country.
- Calculate the volumetric weight and compare it with the real weight to determine the higher weight.
- Calculate the total cost by multiplying the Cost per Pound by the Higher Weight.
3. Use the Trace Function
-
Define CostCalculation as the file name where the traces will be stored.
-
Trace:
- Cost per Pound
- Volumetric Weight
- Real Weight
- Higher Weight
- Shipping Cost
-
Traces using variables: CHelper.trace("CostCalculation", "Volumetric Weight =" + VolumetricWeight);
- Traces using **XPath expressions**:
CHelper.trace("CostCalculation", "Cost =" + <ShippingProcess.Costs>);
- **Compound traces** (using both **variables** and **XPath expressions**):
CHelper.trace("CostCalculation", "Cost per Pound to " + <ShippingProcess.DestinationCountry.Name> + " = " + CostperLb);
4. Run the Process
- Enter values in the required fields.
- Click the button to execute the expression.
5. Access the Trace Log
- Navigate to the trace folder of the project and open the .txt file.
Default Path:
C:\Bizagi\Projects\[project_name]\Trace\
6. View the Trace Output
- The trace log will display the calculated values.