foxtrotZulu
foxtrotZulu

Reputation: 1119

Get reviewer from workflow Item for email notification

Upon Approve or Reject I execute custom email notification that goes like this:

public void Process(WorkflowPipelineArgs args)
    {           
        Assert.ArgumentNotNull(args, "args");
        ProcessorItem processorItem = args.ProcessorItem;
        if (processorItem != null)
        {
            //all variables get initialized
            var site = Sitecore.Configuration.Factory.GetSite("website");
            string contentPath = args.DataItem.Paths.ContentPath;               
            var contentItem = args.DataItem;
            var contentWorkflow = contentItem.Database.WorkflowProvider.GetWorkflow(contentItem);
            var contentHistory = contentWorkflow.GetHistory(contentItem);
            var status = "Approved";

            //Get the item from the master database
            var workflowItem = Sitecore.Context.ContentDatabase.Items[args.DataItem.ID];

            //Get the workflow history so that we can email the last person in that chain.
            if (contentHistory.Length > 0)
            {
                //submitting user (string)
                string lastUser = contentHistory[contentHistory.Length - 1].User;
                //sitecore user (so we can get email address)
                var submittingUser = Sitecore.Security.Accounts.User.FromName(lastUser, false);
                //approve/reject comments
                var comments = args.Comments;

                StringBuilder messageBody = new StringBuilder();

                messageBody.AppendFormat("<div style='font-weight:bold'>Domain: {0}</div>", site.HostName);
                messageBody.AppendLine();
                messageBody.AppendFormat("<div style='font-weight:bold'>Content Item: {0}</div>", contentItem.Paths.FullPath);
                messageBody.AppendLine();
                messageBody.AppendFormat("<div style='font-weight:bold'>Status: {0}</div>", status);
                messageBody.AppendLine();                   
                messageBody.AppendFormat("<div style='font-weight:bold'>Approver Comments: {0}</div>", comments);                    

                MailMessage msg = new MailMessage(FromAddress, submittingUser.Profile.Email);
                msg.Subject = string.Format("{0} - Content item has been approved", site.HostName);
                msg.Body = messageBody.ToString();
                SmtpClient smtpClient = new SmtpClient(MailServer);
                smtpClient.Send(msg);
            }
        }
    }

Problem: I can currently get the reviewer comments but I cant figure out how to get the name or email of the reviewer.

Any Ideas?

Thanks, C

Upvotes: 1

Views: 673

Answers (1)

nickwesselman
nickwesselman

Reputation: 6890

Sitecore.Context.User should give you access to the user who clicked the button, which seems to be what you're looking for.

Upvotes: 3

Related Questions