3

The project I am currently working on requires that content created by members of a content authoring team is approved by a review team in order to publish - this is achieved by a workflow.

I have a requirement that when the reviewer either approves or rejects an item of content, the original author is emailed to tell them that this has happened.

There is an extended email action in place that fires when the reviewer approves or rejects the content, but I am struggling to work my way back from the Item passed in by the WorkflowPipelineArgs to the email address of the original creator - Item.Statistics.CreatedBy returns an empty string.

Web searching has proved fruitless. Can anyone advise?

This is Sitecore 8.1

Thanks.

  • Can you post the part where you want to actually trying to retrieve the item? Also, make sure that the field Created By is populated and I would suggest to make use of the Updated By instead of Created By since the content may be edited by another user. Moreover, try to use something like this item.Fields["__Created by"].Value – Hishaam Namooya Aug 3 '17 at 18:48
4

This post is an old one from Alex Shyba: http://sitecoreblog.alexshyba.com/who_moved_the_item_to_the_workflow_state/

It highlights a way to go back through the workflow history to find a user. This can be more accurate than going to the Created field as an item might go through workflow multiple times, or the user that created an item might not be the one who edits it and sends it into the workflow for review. The code below might need some updating for your version of Sitecore, but the concepts should be accurate.

protected override string GetRecipient(WorkflowPipelineArgs args)
 {
    IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider;

    if (workflowProvider != null)
    {
       IWorkflow workflow = workflowProvider.GetWorkflow(args.DataItem[FieldIDs.Workflow]);

       if (workflow != null)
       {
           WorkflowEvent[] history = workflow.GetHistory(args.DataItem);
           if (history.Length > 0)
           {
               WorkflowEvent wfEvent = history[history.Length - 1];
               string fullUserName = wfEvent.User;

               if (User.Exists(fullUserName))
               {
                  System.Web.Security.MembershipUser mUser = Membership.GetUser(fullUserName);

                  if (mUser.Email != string.Empty)
                  {
                       return mUser.Email;
                  }
               }
           }
        }
     }
  }

 return string.Empty;
}
| improve this answer | |
0

First of all check if "Created by" field in "Statistics" section of item is populated in the content editor under admin user.

If no then something is wrong with updating statistics. And you should fix it.

If "Created by" field is populated then check that reviewer user have permission to read information from "Created By" field(using Access Viewer). And you will be able either give him this rights or use security disabler to get information from "Created by"

using (new Sitecore.SecurityModel.SecurityDisabler())
{
    //Code to get "Create by" field value
}
| 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.