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:
[code lang="csharp"]SPMember usermember = site.Users[this.User.Identity.Name];[/code]
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 lang="csharp"]SPWorkflow.CreateHistoryEvent(this.Web, wf.InstanceId, 0, usermember, time, "", "Some comments here", "");[/code]
In addition to the above, I think you can modify the EventType – in this case 0 to change what appears in the History List.