2

Classic use case. We have "Authors" and "Approvers" roles in our setup. When an item has transitioned from Draft to Review state, we're sending an email notification to a list of "Approvers" to inform then an "Author" has submitted an item through workflow.

I've implemented this through the item saved event using a custom event handler. The rub is, the workflow history hasn't been written at the time the item saved event fires. I've looked through Context.Items dictionary thinking Sitecore might have stowed the comments there but no dice.

Is there a way to capture the workflow comments from the item saved event handler without using Workflow History (since it's not there)?

  • 3
    Why you doing this as a save handler and not just a regular workflow action? – jammykam Aug 2 '17 at 0:59
  • Because... I... didn't... think.... to? – Tim Ellison Aug 2 '17 at 1:01
3

I would change the approach, and as @jammykam mentioned, implement it as an action. The sample workflow, already comes with an action to send emails here: /sitecore/system/Workflows/Sample Workflow/Awaiting Approval/Approve with Test/Action

It is using the class Sitecore.Workflows.Simple.EmailAction, Sitecore.Kernel. I would create my own action using that one as an example, or even inheriting from it.

You have to implement the process method, which receives an object of type WorkflowPipelineArgs. In this object, you have the property CommentFields, a string dictionary with the comments of each field. Once you collect those fields, it is easy to include them in the email.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.