Write to the workflow history list programatically

9 09 2008

Here is the scenario – You wish to write an entry to the workflow history list of a particular workflow but from ‘outside’ the workflow itself e.g. From a SharePoint application page.

Well with the help of Cimares from the SharePoint User Group UK we have managed to produce some code that will do just that, if you pump the right Workflow GUID’s in.

You must first have an SPitem that you wish to query against and an SPMember (This sharepoint user needs to be passed into the code below as the user performing the history event).

To get the current user ID (if you are going to run this code from an application page or similar) use:

SPMember usermember = site.Users[this.User.Identity.Name];

Once you have got those, you can either use a Foreach to iterate through all the workflows on the SPitem and perform the code below or you can specify the instance ID for the specific workflow you wish to write an event to.

Code:

SPWorkflow.CreateHistoryEvent(this.Web, wf.InstanceId, 0, usermember, time, “”, “Some comments here“, “”);

In addition to the above, I think you can modify the EventType – in this case 0 to change what appears in the History List.


Actions

Information

One response

16 10 2009
Malcolm

I need to get the approval date and the approver of a sharepoint document

Leave a comment