Attention

This document was written for an unsupported version of Plone, Plone 2.1.x, and was last updated 1631 days ago.

For more information, see the version support policy.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

Change state recursively in a workflow transition

by cbonnet — last modified Dec 30, 2008 03:02 PM
When transitioning a folderish object, transition all children objects automatically.
Your users might want to transition folderish objects "all in one go": for instance, submit a folder with all the documents in it. Or you have created a complex folderish object with Archetypes and you want your users to see it as a single object, even though it is really a collection of objects.

For all that, you need to transition the children objects automatically when the parent object is transitioned. To this effect, you will need to create a script as follows. Note that this script will apply the same transition to child objects as is being applied to the parent object. Hence, you may get errors if the child objects do not currently support that transition.
#retrieve children objects
children = context.ZopeFind(state_change.object, search_sub=1)

wftool = context.portal_workflow

#loop through the children objects
for _, obj in children:
#transition each object
wftool.doActionFor(obj, state_change.transition.id)


Then, for each transition, apply the script (before, for instance).

You will also need to give the proxy role "Manager" to the script (accessing portal_membership requires "Manage portal" permission).

You are good to go!

Many thanks to Dieter Maurer, Raphael Ritz and Yannick Biet for their help.

Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.