Share and Enjoy !

Sharepoint 2013 App Workflow – Weird Part #1: WriteToHistory has some strange limitations

Generally the WriteToHistory workflow activity is used for one of two purposes:

  1. To leave a simple audit trail of messages for users of a workflow
  2. As a debugging tool for developers

If you’re like me, you have a WriteToHistory activity between almost every major step in your workflow to make sure it’s functioning correctly (although, let’s not forget to take those out before we go to production!).

Let’s look at the WriteToHistory limitation by considering a simple scenario:

  • We have a SharePoint-Hosted App
  • The App includes a single list (such as an Announcements list)
  • The App includes a Visual Studio-authored workflow that is triggered when an item is added to the list

Now, to demonstrate the problem at hand, let’s consider the workflow to be configured as follows:

  • The workflow consists only of a Try/Catch block
  • The Try block includes two WriteToHistory activities: one that writes a “short” message, and one that writes a “long” message
  • The Catch block simply notes any exception that occurs and uses a WriteToHistory activity to record the error

You can see this illustrated in the following figures:

Did I tip my hand there? Yes, the issue here is the length of the message being written. If one attempts to write a message that is longer than 255 characters the entire workflow crashes. No “Catch”… No error message… the workflow simply stops. (As an aside, really?!?!? This is 2014, do we still have to worry about 255 character boundaries?). On the other hand, if I go back and shorten the “longer” message to 255 or less then everything works as expected.

Obviously, we’ll need to make sure we cover our bases on this going forward: never allow a workflow to attempt to write more than 255 characters to the WriteToHistory activity. We can insure this by always calling a method on the string to trim or substring it to a length of 255 or less.

Share and Enjoy !

Related Content: