MOSS Workflow Activity Events
It bugs me when the very ‘supposed’ leaders on MS product ‘code consistency’ don’t follow their own rules. Case in point: MOSS Task Activity events.
For example, the OnTaskChanged event has the following signature: (object sender, ExternalDataEventArgs e)
However the sender is always null. In order to get at the task that raised the event one needs to get at ((SPTaskServiceEventArgs)e).taskId.
Here therefore, are some others I’ve found to help my fellow ‘flow’ers to hook up multiple events to the same handlers (although I’m hoping that SP1 might ‘correct’ the lack of sender consistency):
(object) sender or ((Microsoft.SharePoint.WorkflowActions.CreateTask)sender).ListItemId
1. To get the name of the task that raised the event use sender.ToString().Substring(0, sender.ToString().IndexOf(” “)).
2. You’ll need to populate ListItemId in the designer – due to the nature of when this event is raised, there is no real useful info available prior to the call.
1. To get at the tasks underlying GUID use ((SPTaskServiceEventArgs)e).taskId.
2. (object) sender is always null
1. The tasks GUID can be located with ((Microsoft.SharePoint.WorkflowActions.CompleteTask)sender).TaskId.
2. The tasks name can be isolated with sender.ToString().Substring(0, sender.ToString().IndexOf(” “))
The name of the IfElse activity that raised the event can be found using sender.ToString().Substring(0, sender.ToString().IndexOf(” “)).