开发者

Sitecore workflow approval/rejection emails

开发者 https://www.devze.com 2023-03-13 02:50 出处:网络
We are working on implementing some custom code on a workflow in a Sitecore 6.2 site. Our workflow currently looks something like the following:

We are working on implementing some custom code on a workflow in a Sitecore 6.2 site. Our workflow currently looks something like the following:

Sitecore workflow approval/rejection emails

Our goal is simple: email the submitter whether their content revision was approved or rejected in the "Awaiting Approval" step along with the comments that the reviewer made. To accomplish this we are adding an action under the "Approve开发者_运维技巧" and "Reject" steps like so:

Sitecore workflow approval/rejection emails

We are having two big issues in trying to write this code

  1. There doesn't seem to be any easy way to determine which Command was chosen (the workaround would be to pass an argument in the action step but I'd much rather detect which was chosen)
  2. I can't seem to get the comments within this workflow state (I can get them is the next state though)

For further context, here is the code that I have so far:

var contentItem = args.DataItem;
var contentDatabase = contentItem.Database;
var contentWorkflow = contentDatabase.WorkflowProvider.GetWorkflow(contentItem);
var contentHistory = contentWorkflow.GetHistory(contentItem);

//Get the workflow history so that we can email the last person in that chain.
if (contentHistory.Length > 0)
{
    //contentWorkflow.GetCommands
    var status = contentWorkflow.GetState(contentHistory[contentHistory.Length - 1].NewState);

    //submitting user (string)
    string lastUser = contentHistory[contentHistory.Length - 1].User;

    //approve/reject comments
    var message = contentHistory[contentHistory.Length - 1].Text;

    //sitecore user (so we can get email address)
    var submittingUser = sc.Security.Accounts.User.FromName(lastUser, false);
}


I ended up with the following code. I still see no good way to differentiate between commands but have instead implemented two separate classes (one for approve, one for reject):

public void Process(WorkflowPipelineArgs args)
{
    //all variables get initialized
    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";
    var subject = "Item approved in workflow: ";
    var message = "The above item was approved in workflow.";
    var comments = args.Comments;

    //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;
        var submittingUser = Sitecore.Security.Accounts.User.FromName(lastUser, false);

        //send email however you like (we use postmark, for example)
        //submittingUser.Profile.Email
    }
}


I have answered a very similar question.

Basically you need to get the Mail Workflow Action and then you need to further extend it to use the original's submitter's email.


Easiest way to get the command item itself is ProcessorItem.InnerItem.Parent


This will give you the GUID for commands like submit, reject etc.

args.CommandItem.ID 

This will give you the GUID for states like Draft, approved etc.

args.CommandItem.ParentID
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号