开发者

Sitecore workflow on specific fields of an item

开发者 https://www.devze.com 2022-12-17 16:30 出处:网络
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?

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.

I have since written some code which came out of Steve's reply and an example on this snippet:

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'.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消