Over the years of creating BPMs, I have standardized on how I throw errors and display debugging messages. I thought I would show how I do this especially when there is some C# code that needs some tracing, which can sometimes be difficult. This post is the result of another post I participated in today… thought I would make a separate discussion.
Here are the steps with sample screenshots.
-
Create TWO new variables: dBugMessage and errorMessage:
-
Create your C# code… in the code, we initialize the two variables, and set them as required… here is a code block. Note i am using StringBuilder which takes one additional using statement “using System.Text”. StringBuilder is more efficient than simply appending to your string multiple times.
dBugMessage = ""; //initialize to blank
errorMessage = ""; //initialize to blank
StringBuilder debugger = new StringBuilder();
debugger.AppendLine("@ step 1");
if (1==2) {
debugger.AppendLine("@ step 2");
//wow... this is an error... lets do something
errorMessage = "Houston, we have a problem. 1 should not equal 2";
}
debugger.AppendLine("@ step 3");
dBugMessage = debugger.ToString();
Now I add logic widgets to check if there is an error message and/or debugmessage… if there is, then I display them with widgets. Note that to turn off the debug logic, you simply need to disconnect the second condition widget so that it doesn’t run… OR you can also add a condition that it only shows for certain users or security groups.
Here is a complete display of the logic