More in this section

Forums / Developing with Sitefinity / Sitefinity 3.7 Page Workflow

Sitefinity 3.7 Page Workflow

5 posts, 0 answered
  1. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    29 Jan 2010
    Link to this post
    Hi,

    Please find the 2 images Attached. Work flow which is working in individual pages but not in site map and with multiple pages. Below is the code used which is sending mails  when we approve or decline but not working in site map. Please suggest us.

    using System; 
    using System.Web.UI.WebControls; 
    using Telerik.Workflow; 
    using System.Collections.Generic; 
    using Telerik.Workflow.WebControls; 
    using Telerik.Cms.Engine; 
    using System.Net.Mail; 
    using Telerik.Cms; 
    using Telerik.Security; 
    using System.Configuration; 
    using System.Globalization; 
     
     
     
    public partial class Sitefinity_Admin_ControlTemplates_Pages_PageViewer : System.Web.UI.UserControl 
     
        #region  " Page load " 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            //showing comment text box 
            if (this.workflow.Controls.Count > 0) 
                notificationArea.Visible = true
     
            workflow.Command += new CommandEventHandler(PageWorkflowMenu_Command); 
     
        } 
        #endregion  
     
        #region  " Page Workflow " 
        
        void PageWorkflowMenu_Command(object sender, CommandEventArgs e) 
        { 
            try 
            { 
     
     
                WorkflowInstance workflow = ((WorkflowMenu)sender).GetWorkflow(); 
     
                if (workflow != null) 
                { 
     
                    List<EventActivity> commands = new List<EventActivity>(); 
     
                    this.LoadCommands(commands, workflow.Activity.Activities); 
     
                    int idx = int.Parse((string)e.CommandArgument); 
     
     
                    // The workflow events you could handle are: SendForApproval, Approve, Decline, Publish   
                    // There is no requirement to send out an email upon publish. However, corporate counsel 
                    // might want to have a notification. 
     
                    if ((commands.Count > idx) && !(commands[idx].CommandName.Equals("Publish"))) 
                    { 
     
                        string strRole = string.Empty; 
     
     
                        Telerik.Cms.CmsManager manager = new Telerik.Cms.CmsManager(); 
     
                        Telerik.Cms.ICmsPage page = manager.Provider.GetPageByWorkflow(workflow.ID); 
                        
     
                        MailMessage mailMsg = new MailMessage(); 
     
                         
     
                        //Retrieve the author of the draft. 
                        Int32 numrows; 
                        IList<Telerik.Cms.IStagedPage> hist = page.GetHistory(page.Version, 1, out numrows); 
     
                        string strLanguage = "/" + System.Threading.Thread.CurrentThread.CurrentUICulture.Name;  
     
                        switch (commands[idx].CommandName) 
                        { 
     
     
                            case "SendForApproval": 
     
                                strRole = ConfigurationManager.AppSettings["Approver"].ToString(); 
     
                                //Retrieve approvers 
                                string[] Approvers = Telerik.Security.UserManager.Default.GetUsersInRole(strRole.ToLower()); 
     
     
                                //If there's not an approver, then send it to the administrator. 
                                if (Approvers.Length == 0) 
                                    Approvers = Telerik.Security.UserManager.Default.GetUsersInRole("administrators"); 
     
                                //Add the recipients to message. 
                                foreach (string username in Approvers) 
                                { 
                                    System.Web.Security.MembershipUser user = Telerik.Security.UserManager.Default.GetUser(username); 
                                    mailMsg.To.Add(user.Email); 
                                } 
                                 
                               
     
                                mailMsg.From = new MailAddress(Telerik.Security.UserManager.Default.GetUser(Telerik.Security.UserManager.GetCurrentUser().Identity.Name).Email); 
                                 
                                if (strLanguage.ToString().ToLower()  == "/ar") 
                                { 
                                    mailMsg.Subject = " Arabic - page pending approval"
                                    mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page from  - arabic website has been sent for approval. <br />Comments: " + hiddenTextArea.Value + "  <br /> To approve the page, please go to URL: http://{1}{2}/sitefinity/admin/pages.aspx?select={3}</td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host, strLanguage, page.ID); 
                                } 
                                else 
                                { 
                                    mailMsg.Subject = " English - page pending approval"
                                    mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page from  - english website has been sent for approval. <br />Comments: " + hiddenTextArea.Value + "  <br /> To approve the page, please go to URL: http://{1}{2}/sitefinity/admin/pages.aspx?select={3}</td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host, strLanguage, page.ID); 
                                } 
     
     
                                break; 
     
                            case "Approve": 
     
                                strRole = ConfigurationManager.AppSettings["Publisher"].ToString(); 
         
                                //Retrieve approvers 
                                string[] Publishers = Telerik.Security.UserManager.Default.GetUsersInRole(strRole.ToLower()); 
     
                                //If there's not an publisher, then send it to the administrator. 
                                if (Publishers.Length == 0) 
                                    Publishers = Telerik.Security.UserManager.Default.GetUsersInRole("administrators"); 
     
                                // Add the recipients to message. 
                                foreach (string username in Publishers) 
                                { 
                                    System.Web.Security.MembershipUser user = Telerik.Security.UserManager.Default.GetUser(username); 
                                    mailMsg.To.Add(user.Email); 
                                } 
                                 
                                string strLanguage1 = "/" + System.Threading.Thread.CurrentThread.CurrentUICulture.Name;  
     
     
                                // From: current user 
                                mailMsg.From = new MailAddress(Telerik.Security.UserManager.Default.GetUser(Telerik.Security.UserManager.GetCurrentUser().Identity.Name).Email); 
     
                                //cc: the author to let them know their page has been approved. 
                                mailMsg.CC.Add(new MailAddress(Telerik.Security.UserManager.Default.GetUser(hist[0].Modifier).Email)); 
     
                                if (strLanguage.ToString().ToLower() == "/ar") 
                                { 
     
                                    mailMsg.Subject = " Arabic - page approved"
                                    mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page from  - arabic website has been approved and is ready to be published <br />Comments: " + hiddenTextArea.Value + "  <br /> To approve the page, please go to URL: http://{1}{2}/sitefinity/admin/pages.aspx?select={3}</td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host, strLanguage1, page.ID); 
                                } 
                                else 
                                { 
                                    mailMsg.Subject = " English - page approved"
                                    mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page from  - english website has been approved and is ready to be published <br />Comments: " + hiddenTextArea.Value + "  <br /> To approve the page, please go to URL: http://{1}{2}/sitefinity/admin/pages.aspx?select={3}</td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host, strLanguage1, page.ID); 
                                } 
     
     
                                break; 
     
                            case "Decline": 
     
                                //cc: Let author know that he needs to review/modify. 
                                mailMsg.To.Add(new MailAddress(Telerik.Security.UserManager.Default.GetUser(page.Staged.Modifier).Email)); 
     
                                // From: current user 
                                mailMsg.From = new MailAddress(Telerik.Security.UserManager.Default.GetUser(Telerik.Security.UserManager.GetCurrentUser().Identity.Name).Email); 
     
     
                                if (strLanguage.ToString().ToLower() == "/ar") 
                                { 
                                    mailMsg.Subject = " Arabic - page declined"
                                    mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page from  - arabic website has been declined.<br /> Comments: " + hiddenTextArea.Value + " <br /> </td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host); 
                                } 
                                else 
                                { 
                                    mailMsg.Subject = " English - page declined"
                                    mailMsg.Body += String.Format("<html><body><table><tr><td>The '{0}' page from  - english website has been declined.<br /> Comments: " + hiddenTextArea.Value + " <br /> </td></tr></table></body></html>", page.Name, System.Web.HttpContext.Current.Request.Url.Host); 
                                } 
     
                                break; 
     
     
                        } 
     
                        mailMsg.IsBodyHtml = true
     
                        // Init SmtpClient and send    
                        SmtpClient smtpClient = new SmtpClient(); 
                        smtpClient.Send(mailMsg); 
     
                    } 
     
     
     
                } 
            } 
            catch (Exception ex) 
            { 
                AppLogger.LogError(ex.Message, AppLogger.Severity.Failure); 
            } 
     
        }  
     
        private void LoadCommands(List<EventActivity> commands, IList<Activity> activities) 
        { 
     
            foreach (Activity act in activities) 
            { 
     
                if (act is EventActivity) 
     
                    commands.Add((EventActivity)act); 
     
                this.LoadCommands(commands, act.Activities); 
     
            } 
     
        } 
     
        #endregion 
     
        
    Thanks,
    Karnan

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Jan 2010
    Link to this post
    Hello karnan sekar,

    1. Group operations for workflow works correctly in 3.7 SP2 build 2057.

    2. You are not able to receive an email when you use a group operations with Workflow, because the code you use is for page preview mode, since the group operations uses completely different template - AllPagesList.ascx. In this case your code is not called.

    To get this working you have to create custom view.

    • replace the default GridView control and create your custom one.
    • subscribe for WorkflowActionCommnads.Command event
    • find which checkbox is checked in the GridView

    CheckBox cb = row.FindControl("rowCheck") as CheckBox;

    • get the page id

    System.Web.UI.WebControls.DataKey key = grid.DataKeys[row.RowIndex];
    Guid id = (Guid)key.Values[0];

    • create workflow instance

    WorkflowInstance instance = page.GetWorkflow();

    • check the approval status and send email

    switch (workflow.ApprovalStatus)
      {
                                case ApprovalStatus.Draft:
                                    hasPermission = perm.CheckDemand(PageRights.Modify);
                                    break;
                                case ApprovalStatus.ForApproval:
                                    hasPermission = perm.CheckDemand(PageRights.Approve);
                                    break;
                                case ApprovalStatus.Approved:
                                    hasPermission = perm.CheckDemand(PageRights.Publish);
                                    break;
        }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    01 Feb 2010
    Link to this post
    Hi Ivan Dimitrov,

    I have subscribe work flow Actions in page load. But Check Box Checked is always coming as false. If i subscribe work flow actions in is not post back it is event is not happening.

    Please tell us what wrong in the code.

    #region  " Page load " 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
             
                //showing comment text box 
                if (this.workflowActions.Controls.Count > 0) 
                    //notificationArea.Visible = true
     
                    workflowActions.Command += new CommandEventHandler(WorkflowActionCommnads_Command); 
     
        } 
        #endregion 
     
      void WorkflowActionCommnads_Command(object sender, CommandEventArgs e) 
        { 
          
                 
                 
     
                foreach (GridViewRow row in GridView1.Rows) 
                { 
                     
     
                    CheckBox cb = row.FindControl("rowCheck") as CheckBox; 
                    if (cb.Checked) 
                    { 
                        System.Web.UI.WebControls.DataKey key = GridView1.DataKeys[row.RowIndex]; 
                        Guid id = (Guid)key.Values[0]; 
                    } 
     

    Thanks,
    Karnan
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Feb 2010
    Link to this post
    Hi karnan sekar,

    The server event is executed before your code and you cannot get the checked row of the GridView control. You have to create a custom view as suggested in the previous post.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    01 Feb 2010
    Link to this post
    Hi Ivan Dimitrov,

    Could you please give us some links or samples or documents so that it will help us create soon.

    Thanks,
    karnan
Register for webinar
5 posts, 0 answered