Pedro Costa
Pedro Costa

Reputation: 2996

Leverage Groups for Workflow Approvals

We're implementing a new workflow (combined with staging task sync) on an existing website where we would like to notify all members that "own" that particular section/content to approve changes.

One of the options is to have multiple roles and their corresponding workflows configured for their role and scope, but this seems like overkill - at least for us, as currently one single role is set for approvals (and another for editors)

However I've recently come across this new page property:

enter image description here

And have a couple of questions:

We have a Kentico 11 EMS license and working on an advanced workflow, therefore custom code is possible.

Upvotes: 0

Views: 135

Answers (3)

vasu yerramsetti
vasu yerramsetti

Reputation: 61

Sample code snippet for Custom Global Event Handler for Workflow steps i.e., Reject and Approve steps.

using CMS;
using CMS.Base;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.EmailEngine;
using CMS.EventLog;
using CMS.Helpers;
using CMS.MacroEngine;
using CMS.SiteProvider;
using CMS.WorkflowEngine;
using System;

// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomWorkflowEvent))]

public class CustomWorkflowEvent : CMSModuleLoader
{
    // Module class constructor, the system registers the module under the name "CustomInit"
    public CustomWorkflowEvent()
        : base("CustomInit")
    {
    }

    // Contains initialization code that is executed when the application starts
    protected override void OnInit()
    {
        base.OnInit();

        // Assigns custom handlers to events
        //  WorkflowEvents.Approve.After += WorkFlow_Event_After();
        WorkflowEvents.Reject.After += WorkFlow_Event_After;
        WorkflowEvents.Approve.After += Approve_After;

        // WorkflowEvents.Action.After += WorkFlowAction_Event_After;

    }

    private void Approve_After(object sender, WorkflowEventArgs e)
    {
        try
        {
            WorkflowStepInfo wsi = e.PreviousStep;
            if (wsi != null)
            {
                CMS.WorkflowEngine.Definitions.SourcePoint s = wsi.GetSourcePoint(Guid.NewGuid());
                //Make sure it was an approval (standard) step

                var approvers = WorkflowStepInfoProvider.GetUsersWhoCanApprove(wsi, null, SiteContext.CurrentSiteID, "UserID = " + CMSActionContext.CurrentUser.UserID, "UserID", 0, "Email, FullName, Username");
                EventLogProvider.LogInformation("Approvers Data", "Approvers Data", approvers.ToString());
                if (approvers != null)
                {
                    //Loop through the approvers

                    string siteName = null;
                    SiteInfo si = SiteInfoProvider.GetSiteInfo(SiteContext.CurrentSiteID);
                    if (si != null)
                    {
                        siteName = si.SiteName;
                    }

                    EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("Workflow.Rejected", SiteContext.CurrentSiteName);

                    MacroResolver mcr = MacroResolver.GetInstance();


                    EmailMessage message = new EmailMessage();

                    // Get sender from settings
                    message.EmailFormat = EmailFormatEnum.Both;
                    message.From = eti.TemplateFrom;

                    // Do not send the e-mail if there is no sender specified
                    if (message.From != "")
                    {
                        // Initialize message
                        // message.Recipients = strRecipientEmail;
                        message.Subject = eti.TemplateSubject;

                        // Send email via Email engine API
                        // EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, message, eti, mcr, true);
                    }
                }

            }
        }

        catch (Exception ex)
        {

            throw;
        }

    }

    private void WorkFlow_Event_After(object sender, WorkflowEventArgs e)
    {
        try
        {
            WorkflowStepInfo wsi = e.PreviousStep;
            if (wsi != null)
            {
                CMS.WorkflowEngine.Definitions.SourcePoint s = wsi.GetSourcePoint(Guid.NewGuid());
                //Make sure it was an approval (standard) step

                var approvers = WorkflowStepInfoProvider.GetUsersWhoCanApprove(wsi, null, SiteContext.CurrentSiteID, "UserID = " + CMSActionContext.CurrentUser.UserID, "UserID", 0, "Email, FullName, Username");
                EventLogProvider.LogInformation("Approvers Data", "Approvers Data", approvers.ToString());
                if (approvers != null)
                {
                    //Loop through the approvers

                    string siteName = null;
                    SiteInfo si = SiteInfoProvider.GetSiteInfo(SiteContext.CurrentSiteID);
                    if (si != null)
                    {
                        siteName = si.SiteName;
                    }

                    EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("Workflow.Rejected", SiteContext.CurrentSiteName);

                    MacroResolver mcr = MacroResolver.GetInstance();

                    EmailMessage message = new EmailMessage();

                    // Get sender from settings
                    message.EmailFormat = EmailFormatEnum.Both;
                    message.From = eti.TemplateFrom;

                    // Do not send the e-mail if there is no sender specified
                    if (message.From != "")
                    {
                        // Initialize message
                        // message.Recipients = strRecipientEmail;
                        message.Subject = eti.TemplateSubject;

                        // Send email via Email engine API
                        // EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, message, eti, mcr, true);
                    }
                }




            }
        }

        catch (Exception ex)
        {

            throw;
        }
    }

}

Hope Helps you.

Upvotes: 1

Roman Hutnyk
Roman Hutnyk

Reputation: 1549

  • Can regular CMS users (without membership) be part of a group? - why don't you use roles here?
  • Would we be able to leverage this group for the workflow's email notifications instead of the roles? E.g. email to everyone in the owner group when a page was sent for approval. - you'll need to customize workflow manager class, but in general yes, it is possible. You could find an inspiration in this post
  • Is this option by default inherited from the parent page when a new one is created or does it need to be set individually for each page? - Use a macro to default the field. If you populate it with anything else then the new values will be saved.

Upvotes: 1

vasu yerramsetti
vasu yerramsetti

Reputation: 61

  • Can regular CMS users (without membership) be part of a group?

    It is not part of CMS users. Groups are coming from Groups Application.

GROUP: Allows you to manage user groups. Groups are a social networking feature enabling users to find information and communicate according to shared interests.

  • Would we be able to leverage this group for the workflow's email notifications instead of the roles? E.g. email to everyone in the owner group when a page was sent for approval.

No

  • Is this option by default inherited from the parent page when a new one is created or does it need to be set individually for each page?

No

Upvotes: 0

Related Questions