0
votes

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);
        }
    }
2

2 Answers

0
votes

WorkflowPipeleneArgs have public properties: ID NextStateId and WorkflowState PreviousState, Item CommandItem. You can use them to define item state.

0
votes

WorkflowPipelineArgs have CommandItem , this Item have current state and current command details.

var currentCommandName = arg.CommandItem.Name;