Categories
Bizagi Tips and Tricks

Trace method

The ability to trace information in order to test your code is highly important. After many years of working with Bizagi, I have developed an quite interesting method of tracing the data.

All files are saved in the Trace folder and each case has its unique trace file. I don’t have to mention the usefulness of this approach because it’s quite obvious. Whenever you have to check something related to a particular case, you jump to the Trace folder and search using the case number.

GBL_Trace library rule

The first step is to create a new library rule. Because it’s going to be used all over the processes (in expressions) we must consider it a GLOBAL object. Using notation, I will add the GBL prefix to the name of the library rule. In our case, it will be GBL_Trace.

The library must have two input parameters (sRuleName, sMessage) and one output of type Boolean.

var sFileName, sLogText;

try {
 
    if (Me.Case.CaseNumber == null || Me.Case.CaseNumber == "") {
  
        sFileName = "NoCaseNumber_" + Me.Case.Id.ToString();
   
    } else {
  
        sFileName = Me.Case.CaseNumber;
    }
} catch (e) {
 
    sFileName = CHelper.FormatDate(DateTime.Now, "yyyyMMdd");
}

sLogText = "Rule: " + sRuleName + "; ";

switch (iLevel) {
    case 1:
        sLogText += " Information: ";
        break;
    case 2:
 
        sLogText += " Warning: ";
        break;
    case 3:
        sLogText += " Error: ";
        break;
    default:
        sLogText += " Unknown: ";
        break;
}

 
						  
 
sLogText += "Message: " + sMessage;
CHelper.trace(sFileName, sLogText);

return true;

The library is called as followed:

Global.GBL_Trace(Me,sRuleName,sMessage,1);