Applies to Sitecore 6.0.
In the workflow scenarios with "rejection" commands when an item is moved to a previous workflow state, sometimes necessary to notify the user who submitted the item in the first place.
Since Sitecore keeps track of workflow activities and writes everything into WorkflowHistory table, there are also APIs to retrieve such information.
The code snippet below shows how it can be done.
protected override string GetRecipient(WorkflowPipelineArgs args)
{
IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider;
if (workflowProvider != null)
{
IWorkflow workflow = workflowProvider.GetWorkflow(args.DataItem[FieldIDs.Workflow]);
if (workflow != null)
{
WorkflowEvent[] history = workflow.GetHistory(args.DataItem);
if (history.Length > 0)
{
WorkflowEvent wfEvent = history[history.Length - 1];
string fullUserName = wfEvent.User;
if (User.Exists(fullUserName))
{
System.Web.Security.MembershipUser mUser = Membership.GetUser(fullUserName);
if (mUser.Email != string.Empty)
{
return mUser.Email;
}
}
}
}
}
return string.Empty;
}
This method can be a part of workflow email action that is associated with the "Reject" command.
Related links:
Don't you just love Sitecore workflow?