Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore Workflow and Pipelines

I'm trying to implement a basic Javascript confirmation box on a workflow command (e.g. "are you sure you want to edit this?"). Depending on whether a users clicks yes or no, I want to move to a different state in the workflow. Here is the code I currently have (some logic is taken out):

[Serializable]
public class ConfirmAction
{
    public void Process(WorkflowPipelineArgs args)
    {
        Item currentItem = args.DataItem;
        ClientPipelineArgs clientArgs = new ClientPipelineArgs();
        Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs);
    }

    protected void DialogProcessor(ClientPipelineArgs args)
    {
        if (args.IsPostBack)
        {
            if (args.Result != "yes")
            {
                args.AbortPipeline();
                return;
            }
        }

        else
        {
            Sitecore.Context.ClientPage.ClientResponse.Confirm("Are you sure you want to edit this?");
            args.WaitForPostBack();
        }
    }
}

I'm new to the Pipeline model, especially in relation to Sitecore, so I'm somewhat grasping at straws. The problem that I'm having, I believe, is that I don't have a way of getting the result back to the Workflow Pipeline, from the ClientResponse pipeline, to tell it what to do.

Thank you.

EDIT:

Using Yan's information, I eventually came up with the following solution:

public void Process(WorkflowPipelineArgs args)
{
    Item currentItem = args.DataItem;
    ClientPipelineArgs clientArgs = new ClientPipelineArgs();
    clientArgs.Parameters.Add("itemID", currentItem.ID.ToString());
    clientArgs.Parameters.Add("stateID", currentItem.Fields["__Workflow state"].Value);
    Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs);
}

protected void DialogProcessor(ClientPipelineArgs args)
{
    if (args.IsPostBack)
    {
        if (args.Result != "yes")
        {
            Item currentItem = Sitecore.Configuration.Factory.GetDatabase("master").GetItem(args.Parameters["itemID"]);
            currentItem.Editing.BeginEdit();
            currentItem.Fields["__Workflow state"].Value = args.Parameters["stateID"];
            currentItem.Editing.EndEdit();                   
            return;
        }
        SheerResponse.Eval("window.location.reload();");                
    }

    else
    {
        Sitecore.Context.ClientPage.ClientResponse.YesNoCancel("Are you sure you want to edit this?", "200", "200");
        args.WaitForPostBack();
    }
}
like image 435
raynjamin Avatar asked Dec 23 '10 18:12

raynjamin


People also ask

What is workflow in Sitecore?

A workflow is a series of predefined states that reflect the work processes and procedures for creating web content in your organization. For example, your workflow states could correspond to the creation, review, and approval stages that items must go through before they are published on your website.

What is a Sitecore pipeline?

A pipeline is a series of actions that execute in sequence to perform a task in Sitecore. Pipelines are fundamental to Sitecore's basic architecture. Most processes in Sitecore are defined as pipelines. Pipelines can be modified by developers to change, add, or remove functionality from Sitecore.

How many processors a pipeline can have in Sitecore?

The three processors are called in the order in which they are listed. A parameters object is passed between them to provide continuity.


1 Answers

Well, I think this is where you can take advantage from ClientPipelineArgs. Let's say you add the current item ID to the parameters to pass:

public void Process(WorkflowPipelineArgs args)
{
    Item currentItem = args.DataItem;
    ClientPipelineArgs clientArgs = new ClientPipelineArgs();
    clientArgs.Parameters.Add("id", currentItem.ID.ToString());
    Sitecore.Context.ClientPage.Start(this, "DialogProcessor", clientArgs);
}

and later on when you get positive result you get it back and move to the target workflow state (explained in comments):

protected void DialogProcessor(ClientPipelineArgs args)
{
    if (args.IsPostBack)
    {
        if (args.Result == "yes")
        {
            // 1. take item ID from args.Parameters["id"];
            // 2. get item by this ID
            // 3. move item to target workflow state
        }
    }
    else
    {
        Sitecore.Context.ClientPage.ClientResponse.Confirm("Are you sure you want to edit this?");
        args.WaitForPostBack();
    }
}

This might require some minor changes (I didn't run it myself before posting), but hope you get the idea.

like image 131
Yan Sklyarenko Avatar answered Oct 29 '22 02:10

Yan Sklyarenko