+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / shorten workflow

shorten workflow

11 posts, 0 answered
  1. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    24 Jun 2010
    Link to this post
    Hi

    I want to shorten the workflow to just Save and Publish
    Is this possible?
    If so how?

    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Jun 2010
    Link to this post
    Hello Dave,

    You could skip the stages making some changes programmatically

    for pages you should modify  Sitefinity\Admin\ControlTemplates\Pages\PageViewer.ascx

    private Telerik.Workflow.EventActivity FindActivity(string name, System.Collections.Generic.IList<Telerik.Workflow.Activity> activities)
    {
        foreach (Telerik.Workflow.Activity act in activities)
        {
            if ((act is Telerik.Workflow.EventActivity) && (((Telerik.Workflow.EventActivity)act).CommandName == name))
                return (Telerik.Workflow.EventActivity)act;
            Telerik.Workflow.EventActivity ea = FindActivity(name, act.Activities);
            if (ea != null)
                return ea;
        }
        return null;
    }
     
    private void ExecuteActivity(Guid id, string activityName)
    {
        Telerik.Workflow.WorkflowInstance instance = Telerik.Workflow.WorkflowRuntime.Instance.GetWorkflow(id);
        if (instance != null)
        {
            Telerik.Cms.PageWorkflow workflow = (Telerik.Cms.PageWorkflow)instance.Activity;
            Telerik.Workflow.EventActivity activity = FindActivity(activityName, workflow.Activities);
            if (activity != null)
            {
                activity.Execute(Telerik.Workflow.WorkflowRuntime.Instance);
            }
     
        }
     
     
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        var manager = new Telerik.Cms.CmsManager();
        Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;
        var currentPage = (Telerik.Cms.ICmsPage)manager.GetPage(pageID, true);
        Telerik.Workflow.WorkflowInstance wInstance = currentPage.GetWorkflow();
        if (wInstance != null)
        {
            var activity = (Telerik.Cms.PageWorkflow)wInstance.Activity;
            switch (activity.ApprovalStatus)
            {
                case Telerik.Workflow.ApprovalStatus.Draft:
     
                    ExecuteActivity(currentPage.WorkflowID, "SendForApproval");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    ExecuteActivity(currentPage.WorkflowID, "Approve");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    ExecuteActivity(currentPage.WorkflowID, "Publish");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    manager.SavePage(currentPage);
                    break;
                case Telerik.Workflow.ApprovalStatus.ForApproval:
                   
                    break;
                case Telerik.Workflow.ApprovalStatus.Approved:
                   
                    break;
                case Telerik.Workflow.ApprovalStatus.Published:
                    break;
            }
        }
    }


    for content items you could take a look at this blog post Schedule content items publishing with workflow enabled .
    You have to map the PreviewView of the template and make the changes.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    24 Jun 2010
    Link to this post
    Great thanks

    So its just a simple copy and paste of your code to get it working in pages?

    Thanks
  4. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    25 Jun 2010
    Link to this post
    Hi there,

    I have accomplished this in my previous project and this is the code that worked for me ...

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
     
        var manager = new Telerik.Cms.CmsManager();
        Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;
        var currentPage = (Telerik.Cms.ICmsPage)manager.GetPage(pageID, true);
        Telerik.Workflow.WorkflowInstance wInstance = currentPage.GetWorkflow();
        if (wInstance != null)
        {
            var activity = (Telerik.Cms.PageWorkflow)wInstance.Activity;
    if(currentPage.Status == PageStatus.New) { currentPage.Publish(); manager.SavePage(currentPage); }

            switch (activity.ApprovalStatus)
            {
                case Telerik.Workflow.ApprovalStatus.Draft:
                    ExecuteActivity(currentPage.WorkflowID, "SendForApproval");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    ExecuteActivity(currentPage.WorkflowID, "Approve");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    ExecuteActivity(currentPage.WorkflowID, "Publish");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    manager.SavePage(currentPage);
                    Response.Redirect(Request.RawUrl, false);
                    break;
                case Telerik.Workflow.ApprovalStatus.ForApproval:
                    ExecuteActivity(currentPage.WorkflowID, "Approve");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    ExecuteActivity(currentPage.WorkflowID, "Publish");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    manager.SavePage(currentPage);
                    Response.Redirect(Request.RawUrl, false);
                    break;
                case Telerik.Workflow.ApprovalStatus.Approved:
                    ExecuteActivity(currentPage.WorkflowID, "Publish");
                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
                    manager.SavePage(currentPage);
                    Response.Redirect(Request.RawUrl, false);
                    break;
                case Telerik.Workflow.ApprovalStatus.Published:
                    break;
            }
        }
    }

    There is a simple trick here which is the Response.Redirect(Request.RawUrl, false); 

    Without it you will get the Send For Approval then after you click it again u will see that the page has been published ... Also if you create a new page you need to publish it first.

    Cheers
  5. Tristan
    Tristan avatar
    22 posts
    Registered:
    30 Mar 2009
    08 Sep 2010
    Link to this post
    Hi Ivan. This is exactly what I want to do as well. I've just got one problem.

    When you click save the next option it gives you is Send for Approval which does the publishing. How can I change the text of the Send for Approval button so it says "Publish" instead? I couldn't find a resx file or anything to change.

    Thanks
  6. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    08 Sep 2010
    Link to this post
    Hi Tristan,

    Notice in my code that i have added Response.Redirect(Request.RawUrl, false);

    You should add this too because without it you will always get the send for approval and then the page has been published after the send for approval.

    Cheers,

    George
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Sep 2010
    Link to this post
    Hello,

    The text of the workflow buttons cannot be changed, because it comes from embedded resources for the current culture. The buttons text is updated when you move between workflow steps.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Tristan
    Tristan avatar
    22 posts
    Registered:
    30 Mar 2009
    08 Sep 2010
    Link to this post
    Hi George. If I do that then it just publishes straight after the save. Which is the same if the workflow is turned off. What I want to do is to be able to save a page then have the publish button appear.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Sep 2010
    Link to this post
    Hi Tristan,

    The page can be published if you have executed activity for ApprovalStatus.Published. If you  stop on the activity for Approve the button "Publish" will appear.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Tristan
    Tristan avatar
    22 posts
    Registered:
    30 Mar 2009
    08 Sep 2010
    Link to this post
    Awesome. Thanks guys. That did it. Just need the following in the ApprovalStatus.Draft case.

    ExecuteActivity(currentPage.WorkflowID, "SendForApproval");
    Nolics.ORMapper.Base.DataConnection.InitWebRequest();
    ExecuteActivity(currentPage.WorkflowID, "Approve");                    Nolics.ORMapper.Base.DataConnection.InitWebRequest();                  
    manager.SavePage(currentPage);
    Response.Redirect(Request.RawUrl, false);
  11. Ferenc Papp
    Ferenc Papp avatar
    1 posts
    Registered:
    14 Jun 2010
    25 Jan 2011
    Link to this post
    Response.Redirect caused the page being navigated away from the edited page to the root.
    I have found a solution for this problem: Instead of Response.Redirect I have used:

    workflow.DataBind()

    case Telerik.Workflow.ApprovalStatus.ForApproval:
        //ExecuteActivity(currentPage.WorkflowID, "SendForApproval");
        //Nolics.ORMapper.Base.DataConnection.InitWebRequest();
        ExecuteActivity(currentPage.WorkflowID, "Approve");
        Nolics.ORMapper.Base.DataConnection.InitWebRequest();
        //ExecuteActivity(currentPage.WorkflowID, "Publish");
        //Nolics.ORMapper.Base.DataConnection.InitWebRequest();
        manager.SavePage(currentPage);
        workflow.DataBind();
        break;
Register for webinar
11 posts, 0 answered