Our customers often want to identify the actually executed rules. By default they may look at the automatically generated execution reports in the HTML format – you may find report examples at the OpenRules User Manual p.31. These reports help a rule designer to analyze which rules were executed and in which order. They include the column “Executed Rule #” that contains sequential numbers of executed rules inside their decision tables.
However, these reports are human-oriented and it is not easy to analyze them programmatically to create custom views of actually executed rules. To do this you may define a rule ID directly inside the rules to be used during the execution. You may use the column of the type “#” as the very first column of your decision tables. If you put any ID (text) inside this column for every rule, then this ID will be assigned to the actually executed rule. In the following example
along with the action “Then” we use the action “Message” that identifies the executed rules. If you look at the implementation of the column “Message” in the file “DecisionTableExecuteTemplates.xls”, you will see the following Java snippet:
String out = decision.macro(message);
decision.log(out + ” from ” + $TABLE_TITLE);
Here the method “macro” replaces $RULE_ID with the actual ID of this rule within “message”. You may similarly use this method inside your own custom templates, e.g. to save rule tracing information in your own desired way.