3

Let's say that we have a bunch of items that are already published, meaning that their workflow status must be something like _final. When we move those items from a folder to another in the Content Editor, the workflow status remains the same.

However, I would prefer those items moved from a folder to another folder checked, not just showing those contents to public without any controls.

Is it possible to set the workflow status to something like _Draft so that the user must start their workflow from the beginning when they move their items (contents) to other folders?

1
  • I am going to assume you're using the sitecore sample workflow. For your knowledge a item wont move draft > final back to draft. What happens is draft > final then new version of the item is created and the process starts over. To answer your specific question if you want to change what happens when you copy an item you will have to hook into one of the pipelines and write some custom code.
    – JKerny
    Commented Sep 20, 2018 at 5:05

1 Answer 1

2

You should make use of the event item:moved. In this pipeline, when the item has already been moved, you can update the workflow state.

public void OnItemMovedEvent(object sender, EventArgs args)
{
    var eventArgs = args as SitecoreEventArgs;

    if (eventArgs == null)
    {
        return;
    }

    var item = eventArgs.Parameters[0] as Item;

    // Apply some logics to see if item workflow should be updated

    using (new Sitecore.SecurityModel.SecurityDisabler())
    {       
        item.Editing.BeginEdit();
        item.Fields["__Workflow state"].Value = "{190B1C84-F1BE-47ED-AA41-F42193D9C8FC}";
        item.Editing.EndEdit();     
    }
}

Note that I am assuming you are using the Sample Workflow. If you are using a custom one, you need to update the ID at the statement

item.Fields["__Workflow state"].Value = "{190B1C84-F1BE-47ED-AA41-F42193D9C8FC}";

Once completed, you need to add it to the item event pipeline via config file

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
        <event name="item:saved">
            <handler type="YourNamespace.ClassName,YourAssembly" method="OnItemMovedEvent" />
        </event>
    </events>
  </sitecore>
</configuration>
2
  • Hishaam! Thanks a lot for your answer. It worked!
    – TestUser
    Commented Sep 21, 2018 at 2:34
  • 1
    @Tama can you please approved the answer so that it may help others Commented Sep 21, 2018 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.