Include "Change Note" when creating content from InvokeFactory

I am creating a content item from a Script adapter using invokeFactory

. This is working fine so far, however we want to start generating a comment that will be included in the create action for the item's history. The comment itself will be generated using fields from the form and some predefined text.

Is this possible from PFG?

The content type is a custom type and is available for versions. Using Plone 4.3.2, PFG 1.7.14


My current code:

from Products.CMFPlone.utils import normalizeString

portal_root = context.portal_url.getPortalObject()
target = portal_root['first-folder']['my-folder']
form = request.form
title = "My Title: "+form['title-1']
id = normalizeString(title)
id = id+"_"+str(DateTime().millis())



I tried to use those keys as comments

, comment

, message

and even cmfeditions_version_comment

in the arguments target.invokeFactory

. No luck yet.


source to share

1 answer

I'm not sure if this is possible in a custom adapter script.

First record action None

. The history is automatically displayed Create

if the action None

. This is implemented here (

# On a default Plone site you got the following
>>> item.workflow_history
{'simple_publication_workflow': ({'action': None, 'review_state': 'private', 'actor': 'admin', 'comments': '', 'time': DateTime('2014/10/02 08:08:53.659345 GMT+2')},)}


The dict key is the id of the worker process and the value is a tuple of all records. This way you can manipulate the entry however you want. But I don't know if this is possible with restricted python (custom script adapter can only use restricted python).

But you can also add a new entry by extending your script with


new_object = target.get(id)
workflow_tool = getToolByName(new_object, 'portal_workflow')

workflows = workflow_tool.getWorkflowsFor(new_object)

if not workflows:

workflow_id = workflows[0].id  # Grap first workflow, if you have more, take the the one you need
review_state = workflow_tool.getInfoFor(new_object, 'review_state', None)

history_entry = {
                 'action' : action, # Your action
                 'review_state' : review_state,
                 'comments' : comment, # Your comment
                 'actor' : actor, # Probably you could get the logged in user
                 'time' : time,

workflow_tool.setStatusOf(workflow_id, context, history_entry)




All Articles