Archive

Posts Tagged ‘CreateHistoryEvent’

Workflow Status: Writing to SharePoint Workflow History mapping EventID to Event Type

I recently created a Sequential Workflow using Visual Studio and wanted to display the value of parameters as well as status messages for debugging purposes of the workflow to the Workflow History portion of the Workflow Status page in the browser. I was getting tired of having to go to the ULS logs on the server to look for debug and error messages that I was writing out there. I was able to add items to the Workflow History using the SPWorkFlow.CreateHistoryEvent method. This method allows users to specify the data that is displayed in the workflow history.

TimeSpan time = new TimeSpan(0);

SPWorkflow.CreateHistoryEvent(this.workflowProperties.Web, this.workflowProperties.WorkflowId, eventId, time, “Outcome text”, “Description text”, “Other Data text”);

There are several Event Types (SPWorkflowHistoryEventType) that you can use, as seen in the screenshot below.

The Event Type maps to a specific eventId based on the following table.

EventID

Event Type Member Name Description

 

  None There is no specific event type for this workflow event.

0

Comment WorkflowComment The workflow event concerns a comment being written for the workflow instance.

1

Workflow Initiated WorkflowStarted The workflow event concerns the workflow instance being initiated.

2

Workflow Completed WorkflowCompleted The workflow event concerns the workflow instance being completed.

3

Workflow Cancelled WorkflowCancelled The workflow event concerns the workflow instance being cancelled.

4

Workflow Deleted WorkflowDeleted The workflow event concerns the workflow instance being deleted.

5

Task Created TaskCreated The workflow event concerns a workflow task being created.

6

Task Completed TaskCompleted The workflow event concerns a workflow task being marked as complete.

7

Task Modified TaskModified The workflow event concerns a workflow task being modified.

8

Task Rolled Back TaskRolledBack The workflow event concerns changes to a workflow task being rolled back.

9

Task Deleted TaskDeleted The workflow event concerns a workflow task being deleted.

10

Error WorkflowError The workflow event concerns the workflow instance generating an error.

 

Hope this helps you to debug your visual studio workflows without having to log on to the server and looking through ULS logs, or to just provide workflow status feedback to your users on the Workflow Status page in the browser.