Y'all are going to think I'm pretty slow, but where in the world does Workflow Designer's script editor redirect my Console.Write output?
I haven't been able to use print statements to debug my code. I started writing to a file but that's not nearly as convenient.
Question
Question
Writing to the Console
Answer
You can record messages in the instance details at runtime by using the WorkflowAPI. Look at the TrackInformation, TrackWarning and TrackError methods.
protected override void Execute() { // Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session WorkflowApi.TrackInformation("Hello World!"); WorkflowApi.TrackWarning("Warning! something unexpected but non-terminal happened."); WorkflowApi.TrackError("Something really bad happened, terminating the script now!");
Replies
Cole - Workflow would typically not let you interact with some type of UI but for script debugging their is a method called MsgBox() that will allow you to display a message box if you run the script from within the script editor. Here is a snippet;
Protected Overrides Sub Execute() 'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session MsgBox("Hello World!") End Sub
Because Workflow runs as a service, it has no UI.
The method Miruna points out is the preferred way because it will give usable information not only during development and debugging but also in the production environment allowing for faster troubleshooting of process breakdowns.
Thanks you two!
Marking Miruna's response as the answer just because it seems like it would be a better solution for debugging purposes.
Cliff, thanks for clarifying that workflow doesn't like outside UIs, I figured I just couldn't find the console window.
I know I should start a thread for this separately, but is it possible to use WorkflowActivities within a method other than Execute()? I can't find mention of them in the SDK docs, so I have no idea how they actually work. It looks like there's a WorkflowApi class but at the same time there's an IWorkflowAPI interface?
I tried creating a class that inherits IWorkflowApi but that's not going over too well.
I'm not quite sure what you're asking. What are you trying to accomplish?
In short, I want to run WorkflowApi.Trackinformation() from outside the main method in a workflow SDK script.
If I'm in the main method, it works perfectly, but the second there's a second method, such as
public void ThisMethod() { WorkflowApi.Trackinformation("Borked. Will not run."); }
then the Trackinformation and WorkflowApi stuff disappear and won't work.
Cole - This example works for me;
namespace WorkflowActivity.Scripting.SDKScript2 { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Text; using Laserfiche.RepositoryAccess; /// <summary> /// Provides one or more methods that can be run when the workflow scripting activity is performed. /// </summary> public class Script1 : RAScriptClass92 { /// <summary> /// This method is run when the activity is performed. /// </summary> protected override void Execute() { // Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session TrackMessage(); } public void TrackMessage() { WorkflowApi.TrackInformation("Hello World!!"); } } }
This is similar to what I'm looking to do, but my version is non static, and as such the compiler yells at me when I try to build my script.
I'd like to pass a string as a variable to something like TrackMessage and use that variable as the output string for the TrackInformation method.
Cole - Here is an example of how you can do that;
using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.ComponentModel; using System.Data.SqlClient; using System.Text; using Laserfiche.RepositoryAccess; namespace WorkflowActivity.Scripting.SDKScript { ///<summary> ///Provides one or more methods that can be run when the workflow scripting activity is performed. ///</summary> public class Script1 : RAScriptClass92 { //Use enum to pass message type to track private enum MessageType { TrackInformation, TrackWarning, TrackError } ///<summary> ///This method is run when the activity is performed. ///</summary> protected override void Execute() { //Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session //An information message... this.TrackMessage("FYI!", MessageType.TrackInformation); //A warning message... this.TrackMessage("This is a warning", MessageType.TrackWarning); //An error... this.TrackMessage("This is an error", MessageType.TrackError); } private void TrackMessage(string msgText, MessageType msgType) { switch (msgType) { case MessageType.TrackInformation: this.WorkflowApi.TrackInformation(msgText); break; case MessageType.TrackWarning: this.WorkflowApi.TrackWarning(msgText); break; case MessageType.TrackError: this.WorkflowApi.TrackError(msgText); break; } } } }
I forgot about "this." Of all the important keywords to forget, "this" is probably one of the worst. Can you tell I haven't been practicing my programming in a while?
Thank you Cliff! My program now functions properly and I can debug future programs as well.