As part of the Sitecore workflow, how can I get the command name that executed the action? For example,
I have 3 states: Accept, Draft, Review and the Draft and Review both have a custom Email Action that should look at a different dictionary item depending on command that executed (Save or Submit in the drafting state and Approve or Reject in the review state). I would like to use the current workflow state and the command to determine which dictionary item to pull, how can I do that? Here is the function that I'm using.
public void Process(WorkflowPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
var processorItem = args.ProcessorItem;
if (processorItem == null)
{
return;
}
var currentItem = args.DataItem;
var innerItem = processorItem.InnerItem;
var fullPath = innerItem.Paths.FullPath;
var recipient = currentItem.Fields["Primary Email"].Value;
var candidateName = currentItem.Fields["Candidate Name"].Value;
var formName = currentItem.Name;
if (string.IsNullOrEmpty(recipient)) return;
var from = GetText(innerItem, "from", args);
var mailServer = GetText(innerItem, "mail server", args);
var currentWorkflowState = currentItem.Fields[FieldIDs.WorkflowState].Value;
var subject = string.Format(Translate.Text("cb-candidate-submission-subject"), formName);
var message = string.Format(Translate.Text("cb-candidate-submission-body"), candidateName, formName);
Error.Assert(@from.Length > 0, "The 'From' field is not specified in the mail action item: " + fullPath);
Error.Assert(subject.Length > 0,
"The 'Subject' field is not specified in the mail action item: " + fullPath);
Error.Assert(mailServer.Length > 0,
"The 'Mail server' field is not specified in the mail action item: " + fullPath);
var mailMessage = new MailMessage();
mailMessage.To.Add(recipient);
mailMessage.From = new MailAddress(@from);
mailMessage.Subject = subject;
mailMessage.Body = message;
var client = new SmtpClient(mailServer) { EnableSsl = false };
try
{
client.Send(mailMessage);
}
catch (Exception ex)
{
Log.Error("EmailExAction Threw An Exception", ex, this);
}
}