You should use the event item:saved
. When you have saved the item, in the handler, you will be able to extract the item which has been saved. Based on the item, you can retrieve the parent item. Then, check if the parent item's template is derived from a template that you want to update the workflow.
The reason you need to check for the parent item is becaue you don't want the workflow state to be updated for all the items.
public void OnItemSaved(object sender, EventArgs args)
{
var eventArgs = args as SitecoreEventArgs;
var item = eventArgs?.Parameters[0] as Item;
if (item != null)
{
var parentItem = item.Parent;
if (ProcessShouldSkipped(parentItem))
{
return;
}
using (new SecurityDisabler())
{
parentItem.Editing.BeginEdit();
parentItem.Fields["__Workflow state"].Value = "ID of your workflow state";
parentItem.Editing.EndEdit(true);
}
}
}
public static bool ProcessShouldSkipped(Item parentItem)
{
return !parentItem.Template.ID.Equals(new ID("ID of your template"));
}
And you need to patch the new handler to the item:saved
event.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="item:saved">
<handler type="YourNamespaceWithClassName,YourAssemblyName" method="OnItemSaved" />
</event>
</events>
</sitecore>
</configuration>
Note that in this code snippet the template ID has been hard coded. You can create a setting either in Siteceore or in a config file. Then use the setting to see if the item workflow should be updated.