tags:

views:

337

answers:

1

In Sitecore is it possible to have a workflow set up such that changing some field of an item does not cause the item to go to approval states?

We would like to have several fields editable and immediately publishable, while enforcing workflow for a change to one specific field. This field if edited would pass the item to the 'Awaiting Approval' state.

I didn't find anything on how to do this in the reference: http://sdn.sitecore.net/upload/sitecore6/sc61keywords/workflowreference-a4.pdf

I have since written some code which came out of Steve's reply and an example on this snippet: http://sdn.sitecore.net/faq/api/cause%20the%20workflow%20to%20invoke%20an%20action.aspx

class Filter
{
    public void Process(WorkflowPipelineArgs args)
    {
        Database master = Factory.GetDatabase("master");
        Item item = args.DataItem;
        IWorkflow wf = master.WorkflowProvider.GetWorkflow(item);
        AllowPublishIfNoChangeToBodyField(item, wf);
    }

    /// <summary>
    /// If the item's 'Body' field was not modified change the workflow state to Pending Publication
    /// by running the Approve and Submit for Publication command
    /// </summary>
    /// <param name="item"></param>
    /// <param name="wf"></param>
    void AllowPublishIfNoChangeToBodyField(Item item, IWorkflow wf)
    {
        using (new Sitecore.SecurityModel.SecurityDisabler())
        {
            if (true//pseudo code for now: body wasn't modified)
            {
                wf.Execute("{command-id}", item, "allow edits and publishing of all fields other than 'Body'", false); 
            }
        }
    }
}

The problem is The 'Next State' of the 'Command' overwrites whatever state change I make to the item in the 'Action'.

+6  A: 

Hi David,

Sounds like a custom workflow action would do the trick, have it fire when the user submits the change and programmatically check for changes on the field.

If a change has been made move the workflow into the 'Awaiting Approval' state, if not just exit and let it pass into the auto-publish state.

There is a snippet on the sdn aptly titled "Changing the Workflow State on an Item via API", I haven't tried it myself but it should probably do the trick.

Steve Green
Steve,I have updated my question, to include some new code. The changes to the workflow (I have validated the state was changed with item.State.GetWorkflowState()) aren't saving after the action. I think the remainder of the 'Command' which is to switch State to the command's 'Next State field' is being processed after my action. Any thoughts?Thanks!
David