Logging Workflows for Troubleshooting

May 16, 2008 at 1:31 pm 8 comments

SharePoint workflows are very powerful tools. SharePoint workflows allow you to automate tasks and workflow processes. If you haven’t used workflows before, I recommend reading the SharePoint online help for workflows:

http://office.microsoft.com/en-us/sharepointdesigner/CH100667661033.aspx

Once you start to use workflows in your SharePoint applications, you realise a very important and fundamental truth; what happens when a workflow fails? By default, you can click on an item in a list and see the workflow history. Unfortunately, the error messages in the workflow can be cryptic to say the least. For example, if I have a workflow that creates new items in 5 different lists and the workflow fails, I get a message saying “Unable to update list item”. The message doesn’t tell me which specific action or step failed or which list it was unable to write to.

To get around this issue, and to provide an even finer level of control over my workflows, I created a custom list and used that list to log my workflow actions. The custom list, called WorkflowLog, contains the following fields:

  • Workflow Name (text field) – stores the name of the workflow that is logging the event.
  • EventOccurred (date & time field) – stores the date and time that the event was completed.
  • Workflow Step (text field) – stores the number and label of the step being completed.
  • Workflow Action (text field) – stores the specific action step completed.
  • Event (multiple line text field) – stores details about the action completed.
  • AdminNotes (multiple line text field) – allows me to store specific notes for troubleshooting.

I configure my workflows to write an entry to the WorkflowLog everytime an important step is completed. If the workflow creates a new item and sets the status to ‘Created’, the next action is to create a new item in the workflow log and log that creation. Here is an example of the line item created by my Auto-increment ClientID workflow:

WorkflowName

AutoAssignClientID 

EventOccurred

5/15/2008 2:03 PM 

WorkflowStep

1 – Update ClientID then Increment ClientID 

WorkflowAction

Updated the ClientID on the new client 

Event

The workflow has taken the latest ClientID from the SystemCounters database and updated the Customer. Then it has incremented the SystemCounters by one.

AdminNotes

You can see, from the example, that I know that the workflow ran step 1 at 2:03pm on 5/15/2008. I know the step completed, and what it did. The link in the Admin Notes opens the original item so that I can check it. The workflow log allows you to easily troubleshoot a failed workflow – and it has the advantage that it works for Custom Form Actions (which have no history at all?).

Organising the Log

The log continues to compile workflow entries in the background as my users continue to work in the application. I can sort the log by the date the event occurred or by the workflow name, etc. I also have another field, specific to my company, which contains the “ticket number”. I can sort the workflow log by the specific ticket number, then the workflow name, and then the date and time. I have an admin page that contains a multiple item dataview of the log and allows me to select the ticket number from a drop-down list to filter the available entries. 

Future efforts

I am going to add a new column and link to the workflow. I want a column that stores a link to the actual SharePoint workflow history. If you open the workflow history on an existing item, the URL in the address bar looks like this:

http://mysharepointsite/sites/main/_layouts/Workflow.aspx?ID=72&List=B65934BA-EBF4-4CB8-956D-B0Ce4236B657 

The ID number identifies which specific entry the workflow was run on and the List number identifies which list the entry resides in. I will create a hyperlink that takes the ID from the current item (Dataview) and substitutes the List number as a variable as well.

I think that this log process contains a lot of untapped potential and I will be updating this post as I add to the log.

UPDATE

Paul Galvin pointed out that I forgot to mention some  of the possible downfalls to this logging method. You can see his blog here

Thanks for Reading

Advertisements

Entry filed under: SharePoint Designer, SharePoint Tips and Tricks. Tags: , , , .

Create a Virtual Time Card System Web Application Design (part 1)

8 Comments Add your own

  • 1. Jason Rakowski  |  May 16, 2008 at 2:03 pm

    Good Layout and design. I like your blog. I just added your RSS feed to my Google News Reader. .

    Jason Rakowski

    Reply
  • […] Well, Sanjeev Rajput beat me to it.  Have a look.  […]

    Reply
  • 3. Paul Galvin  |  May 18, 2008 at 12:18 pm

    Great post.

    I was going to blog on this subject too, but you beat me to the punch 🙂

    I did blog about it, but referred to yours and added a few of my own thoughts here: http://feeds.feedburner.com/~r/PaulGalvinsSharepointSpace/~3/292810313/cns!1CC1EDB3DAA9B8AA!1092.entry

    –Paul Galvin

    Reply
  • […] Well, Sanjeev Rajput beat me to it.  Have a look.  […]

    Reply
  • 5. ThiNg  |  June 11, 2008 at 7:29 pm

    Thanks for the feedback Jason. I hope you enjoy the new tips I posted today as well.

    Reply
  • 6. Richard Jacobs  |  June 12, 2008 at 2:51 pm

    Hi,

    Great blog!

    I have been in discussion with my project manager about how to extend the workflow history list (as it doesnt hold enough detail) and this is perfect!

    Question though, I am writing a custom workflow in VS2008, how can write to a custom list using c#?

    Many thanks

    Reply
  • 7. ThiNg  |  June 12, 2008 at 3:51 pm

    Hi Richard,

    Thanks for reading. I appreciate the feedback.

    Everything I have read says that it is better to create the custom list in SharePoint from the browser. I don’t even use SharePoint Designer to create new lists, I always go back to the browser and create them. Once the custom list is made, it can be referenced from your workflow code.

    Regards

    Sanj

    Reply
  • 8. Chris  |  February 2, 2010 at 10:44 pm

    Alternatively, you can leverage the Workflow History List to display your custom messages.

    If using declarative workflows, (1) build a string variable using the Action “Build Dynamic String” and (2) log the string variable as the message using the Action “Log to History List”.

    If using non-declarative workflows (i.e. Visual Studio workflows), (1) use the SPWorkflow method “CreateHistoryEvent”.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Top Posts


%d bloggers like this: