You are viewing limited content. For full access, please sign in.

Question

Question

Writing to the Console

asked on August 12, 2015

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.

1 0

Answer

SELECTED ANSWER
replied on August 12, 2015

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!");

4 0
replied on August 12, 2015

The caveat being to make sure you comment out or remove non-essential message tracking when you move to production as these messages are stored with the workflow.

2 0

Replies

replied on August 12, 2015 Show version history

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

 

2 0
replied on August 12, 2015

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.

2 0
replied on August 12, 2015

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.

0 0
replied on August 13, 2015

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.

0 0
replied on August 13, 2015

I'm not quite sure what you're asking. What are you trying to accomplish?

0 0
replied on August 13, 2015

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.

0 0
replied on August 13, 2015 Show version history

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!!");
        
        }
        
    }
}

 

1 0
replied on August 18, 2015

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. 

0 0
replied on August 18, 2015

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;
			}

		}

	}

}

 

2 0
replied on August 19, 2015

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.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.