Sitecore Desktop Approval / Rejection Protocols

We are working on introducing some custom code into the workflow on Sitecore 6.2. Currently, our workflow looks something like this:

example sitecore workflow

Our goal is simple: send an e-mail to the applicant whether their version of the content was approved or rejected in the “Pending approval” step, together with the comments made by the reviewer. To do this, we add the action under the “Approve” and “Reject” steps as follows:

sitecore workflow with actions

We have two big problems trying to write this code.

  • There seems to be no easy way to determine which command was selected (a workaround would be to pass the argument in the step of the action, but I would rather find out what was selected)
  • ( )

, , :

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);
}
+5
4

. - , ( , ):

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
    }
}
+7

.

, , .

+3

The easiest way to get the command element itself is ProcessorItem.InnerItem.Parent

0
source

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

args.CommandItem.ID 

This will give you a GUID for states like draft, approved, etc.

args.CommandItem.ParentID
0
source

All Articles