When an item is rejected by a reviewer in the workflow process, how do I inform the submitter? This seems like a very common situation, but I just see the most basic fields
Get the Mail Workflow Action from the shared source workflow actions.
Then you need to extend Populate context a little bit to make access to the last users easier. Here is my implementation on one of our recent projects:
protected virtual void PopulateContext(WorkflowPipelineArgs args)
{
VelocityContext.Put("args", args);
var item = args.DataItem;
VelocityContext.Put("item", item);
VelocityContext.Put("language", item.Language.CultureInfo.EnglishName);
VelocityContext.Put("version", item.Version.Number);
VelocityContext.Put("comment", args.Comments);
VelocityContext.Put("processor", args.ProcessorItem);
VelocityContext.Put("user", Context.User);
Database masterDatabase = Factory.GetDatabase(DatabaseNames.Master);
var workflow = masterDatabase.WorkflowProvider.GetWorkflow(item);
var history = workflow.GetHistory(item);
VelocityContext.Put("history", history);
if (history.Length > 0)
{
string lastUser = history[history.Length - 1].User;
MembershipUser membership = Membership.GetUser(lastUser);
VelocityContext.Put("authorEmail",
membership != null
? membership.Email
: DataAccessSettings.Workflow.WebQueryEmail);
}
VelocityContext.Put("state", workflow.GetState(item));
var nextStateItem = GetNextState(args);
VelocityContext.Put("nextState", nextStateItem != null ? nextStateItem.Name : string.Empty);
VelocityContext.Put("time", DateTime.Now);
VelocityContext.Put("previewUrl", string.Format("http://{0}/?sc_itemid=%7b{1}%7d&sc_mode=preview&sc_lang=en", DataAccessSettings.Site.HostName, item.ID.Guid));
VelocityContext.Put("contentEditorUrl", string.Format("http://{0}/sitecore/shell/Applications/Content%20editor.aspx?fo=%7b{1}%7d&id=%7b{1}%7d&la=en&v=1&sc_bw=1", DataAccessSettings.Site.HostName, item.ID.Guid));
}
///
/// Processes the template, expanding all known values
///
/// Template to process
/// Rendered template
protected virtual string ProcessValue(string value, Item item)
{
var result = new StringWriter();
try
{
Velocity.Evaluate(VelocityContext, result, "Extended mail action", value);
}
catch (ParseErrorException ex)
{
Log.Error(string.Format("Error parsing template for the {0} item \n {1}",
item.Paths.Path, ex), this);
}
return result.GetStringBuilder().ToString();
}
#region helpers
private static Item GetNextState(WorkflowPipelineArgs args)
{
Item command = args.ProcessorItem.InnerItem.Parent;
string nextStateID = command["Next State"];
if (nextStateID.Length == 0)
{
return null;
}
return args.DataItem.Database.Items[ID.Parse(nextStateID)];
}
private string ProcessFieldValue(string fieldName, Item item)
{
string value = item[fieldName];
if (value.Length > 0)
{
return ProcessValue(value, item);
}
return value;
}
#endregion
You can use $authoremail when setting up the email template.
Hope that helps.