Hello,
This is my first post with Sitecore. Be gentle 🙂 . I am open to suggestions to improve the code and the blog. Thank you
Requirements: When an item of a specific template is submitted or approved add new task with a future due date for review (3 months) set new message and the email of the submitter.
Here is the code for the custom “Set Reminder” action.
public class SetReminder
{
// Methods
public void Process(WorkflowPipelineArgs args)
{
var contentItem = args.DataItem;
var contentWorkflow = contentItem.Database.WorkflowProvider.GetWorkflow(contentItem);
var contentHistory = contentWorkflow.GetHistory(contentItem); //this is the Content History array
string filteredTemplates = "{5EE4099D-C044-4090-92C2-DF4BFD9D180B}|{E4A8BDD6-8F6E-44CA-99C3-6B4CFF2531BA}|{35C51626-A64C-4D98-BF7E-FE08BEEA5E8A}|{5281A860-3EBD-431D-9226-8A7F635C4F04}";
if (filteredTemplates.Contains(contentItem.TemplateID.ToString()) && contentHistory.Length > 0)
{
//get submitting user’s email
string lastUser = contentHistory[contentHistory.Length – 1].User;
var submittingUser = Sitecore.Security.Accounts.User.FromName(lastUser, false);
string useremail = submittingUser.Profile.Email; //original submitter
//Use a security disabler to allow changes
using (new Sitecore.SecurityModel.SecurityDisabler())
{
contentItem.Editing.BeginEdit();
try
{
//perform the editing
contentItem.Fields[“__reminder recipients”].Value = string.Format(“{0};{1}”,”webeditor@cipfa.org”, useremail );
contentItem.Fields[“__reminder text”].Value = “This item is due for review”;
Sitecore.Data.Fields.DateField dateField = contentItem.Fields[“__reminder date”];
DateTime auxDateTime = DateTime.Today.AddMonths(3);
dateField.Value = string.Format(“{0}{1}{2}T{3}”,
auxDateTime.Year,
auxDateTime.Month,
auxDateTime.Day,
auxDateTime.ToString(“hhmmss”));
}
finally
{
//Close the editing state
contentItem.Editing.EndEdit();
}
}
}
}
You need to create the action under which command you want and place the method and the namespace in the “Type string” field.
Best Regards,
Viorel